-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
214 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Gtk; | ||
|
||
class MyCellRenderer : CellRenderer { | ||
|
||
/* icon property set by the tree column */ | ||
public Gdk.Pixbuf icon { get; set; } | ||
|
||
public MyCellRenderer () { | ||
GLib.Object (); | ||
} | ||
|
||
/* get_size method, always request a 50x50 area */ | ||
public override void get_size (Widget widget, Gdk.Rectangle? cell_area, | ||
out int x_offset, out int y_offset, | ||
out int width, out int height) | ||
{ | ||
x_offset = 0; | ||
y_offset = 0; | ||
width = 50; | ||
height = 50; | ||
} | ||
|
||
/* render method */ | ||
public override void render (Cairo.Context ctx, Widget widget, | ||
Gdk.Rectangle background_area, | ||
Gdk.Rectangle cell_area, | ||
CellRendererState flags) | ||
{ | ||
Gdk.cairo_rectangle (ctx, background_area); | ||
if (icon != null) { | ||
/* draw a pixbuf on a cairo context */ | ||
Gdk.cairo_set_source_pixbuf (ctx, icon, | ||
background_area.x, | ||
background_area.y); | ||
ctx.fill (); | ||
} | ||
} | ||
} | ||
|
||
Gdk.Pixbuf open_image () { | ||
try { | ||
return new Gdk.Pixbuf.from_file ("/usr/share/pixmaps/debian-logo.png"); | ||
} catch (Error e) { | ||
error ("%s", e.message); | ||
} | ||
} | ||
|
||
int main (string[] args) { | ||
Gtk.init (ref args); | ||
|
||
var tv = new TreeView (); | ||
var tm = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string)); | ||
tv.set_model (tm); | ||
|
||
var renderer = new MyCellRenderer (); | ||
var col = new TreeViewColumn (); | ||
col.pack_start (renderer, true); | ||
col.set_title ("1st column"); | ||
col.add_attribute (renderer, "icon", 0); | ||
|
||
TreeIter ti; | ||
tm.append (out ti); | ||
tv.append_column (col); | ||
|
||
var pixbuf = open_image (); | ||
tm.set (ti, 0, pixbuf, 1, "asd", -1); | ||
col.add_attribute (renderer, "icon", 0); | ||
|
||
var win = new Window (); | ||
win.set_default_size (400, 100); | ||
win.destroy.connect (Gtk.main_quit); | ||
win.add (tv); | ||
win.show_all (); | ||
Gtk.main (); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
class Helper { | ||
|
||
/** | ||
* Return the screen dimentions in pixels that containes the passed-in window. | ||
*/ | ||
public static Gdk.Rectangle getScreenSizeForWindow(Gtk.Window window) { | ||
var gdkWindow = window.get_window(); | ||
var display = Gdk.Display.get_default(); | ||
var monitor = display.get_monitor_at_window(gdkWindow); | ||
return monitor.get_geometry(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,24 @@ | ||
using Gtk; | ||
using Gdk; | ||
|
||
public class RemontoireWindow : Gtk.Window { | ||
int main (string[] args) { | ||
var app = new Gtk.Application ("org.regolith.remontoire", ApplicationFlags.FLAGS_NONE); | ||
app.activate.connect (() => { | ||
var win = app.active_window; | ||
if (win == null) { | ||
win = new Remontoire.Window (app); | ||
} | ||
|
||
public RemontoireWindow () { | ||
this.set_skip_taskbar_hint(true); | ||
this.set_skip_pager_hint(true); | ||
this.set_decorated(false); | ||
this.set_resizable(false); | ||
this.set_default_size(200, 400); | ||
//this.set_gravity(NORTH_EAST); | ||
this.set_type_hint(DIALOG); | ||
this.stick(); | ||
var geometry = Helper.getScreenSizeForWindow(win); | ||
int height, width; | ||
|
||
var view = new TreeView (); | ||
setup_treeview (view); | ||
add (view); | ||
this.destroy.connect (Gtk.main_quit); | ||
} | ||
win.show_all (); | ||
|
||
private void setup_treeview (TreeView view) { | ||
var padding = 5; | ||
win.get_size(out width, out height); | ||
var x_position = geometry.width - width - padding; | ||
var y_position = 0 + padding; | ||
|
||
var store = new TreeStore (2, typeof (string), typeof (string)); | ||
view.set_model (store); | ||
win.move(x_position, y_position); | ||
}); | ||
|
||
view.insert_column_with_attributes (-1, "Product", new CellRendererText (), "text", 0, null); | ||
view.insert_column_with_attributes (-1, "Price", new CellRendererText (), "text", 1, null); | ||
|
||
//TreeIter root; | ||
TreeIter category_iter; | ||
TreeIter product_iter; | ||
|
||
//store.append (out root, null); | ||
//store.set (root, 0, "All Products", -1); | ||
|
||
store.append (out category_iter, null); | ||
store.set (category_iter, 0, "Books", -1); | ||
|
||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Moby Dick", 1, "$10.36", -1); | ||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Heart of Darkness", 1, "$4.99", -1); | ||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Ulysses", 1, "$26.09", -1); | ||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Effective Vala", 1, "$38.99", -1); | ||
|
||
store.append (out category_iter, null); | ||
store.set (category_iter, 0, "Films", -1); | ||
|
||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Amores Perros", 1, "$7.99", -1); | ||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Twin Peaks", 1, "$14.99", -1); | ||
store.append (out product_iter, category_iter); | ||
store.set (product_iter, 0, "Vertigo", 1, "$20.49", -1); | ||
|
||
view.expand_all (); | ||
} | ||
|
||
public static int main (string[] args) { | ||
Gtk.init (ref args); | ||
|
||
var window = new RemontoireWindow (); | ||
|
||
window.show_all (); | ||
|
||
var gdkWindow = window.get_window(); | ||
var display = Display.get_default(); | ||
var monitor = display.get_monitor_at_window(gdkWindow); | ||
var geometry = monitor.get_geometry(); | ||
|
||
window.move(geometry.width - 230, 10); | ||
Gtk.main (); | ||
|
||
return 0; | ||
} | ||
} | ||
return app.run (args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
remontoire_sources = [ | ||
'main.vala' | ||
'main.vala', | ||
'window.vala', | ||
'helper.vala' | ||
] | ||
|
||
remontoire_deps = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using Gtk; | ||
using Gdk; | ||
|
||
namespace Remontoire { | ||
|
||
/** | ||
* Primary window to dispay keybindings. | ||
*/ | ||
public class Window : Gtk.Window { | ||
|
||
public Window (Gtk.Application app) { | ||
Object (application: app); | ||
|
||
style_window(this); | ||
|
||
var view = new TreeView (); | ||
setup_treeview (view); | ||
add (view); | ||
this.destroy.connect (Gtk.main_quit); | ||
} | ||
|
||
private void setup_treeview (TreeView view) { | ||
var store = new TreeStore (2, typeof (string), typeof (string)); | ||
view.set_model (store); | ||
|
||
view.insert_column_with_attributes (-1, "Action", new CellRendererText (), "text", 0, null); | ||
view.insert_column_with_attributes (-1, "Keybinding", new CellRendererAccel (), "text", 1, null); | ||
|
||
TreeIter action_iter; | ||
TreeIter binding_iter; | ||
|
||
add_category(store, out action_iter, "Launch"); | ||
|
||
add_item(store, action_iter, out binding_iter, "Terminal", "<Super> Return"); | ||
add_item(store, action_iter, out binding_iter, "Browser", "<Super> <Shift> Enter"); | ||
add_item(store, action_iter, out binding_iter, "Application", "<Super> Space"); | ||
add_item(store, action_iter, out binding_iter, "Command", "<Super><Shift> Space"); | ||
add_item(store, action_iter, out binding_iter, "Control Center", "<Super> c"); | ||
|
||
add_category(store, out action_iter, "Navigate"); | ||
|
||
add_item(store, action_iter, out binding_iter, "Window by Name", "<Super><Ctrl> Space"); | ||
add_item(store, action_iter, out binding_iter, "Relative Window", "<Super> ↑ ↓ ← →"); | ||
add_item(store, action_iter, out binding_iter, "Relative Window", "<Super> k j h l"); | ||
add_item(store, action_iter, out binding_iter, "Workspace 0 - 9", "<Super> 0…9"); | ||
add_item(store, action_iter, out binding_iter, "Workspace 10 - 19", "<Super><Ctrl> 0…9"); | ||
add_item(store, action_iter, out binding_iter, "Previous Workspace", "<Super><Shift> Tab"); | ||
add_item(store, action_iter, out binding_iter, "Next Workspace", "<Super> Tab"); | ||
|
||
|
||
add_category(store, out action_iter, "Modify"); | ||
|
||
add_item(store, action_iter, out binding_iter, "Next Window Orientation", "<Super> Backspace"); | ||
add_item(store, action_iter, out binding_iter, "Gaps Between Windows", "<Super> + -"); | ||
add_item(store, action_iter, out binding_iter, "Window Position", "<Super><Shift> ↑ ↓ ← →"); | ||
add_item(store, action_iter, out binding_iter, "Window Position", "<Super><Shift> k j h l"); | ||
add_item(store, action_iter, out binding_iter, "Workspace of Window", "<Super><Shift> 0…9"); | ||
add_item(store, action_iter, out binding_iter, "Window Fullscreen Toggle", "<Super> f"); | ||
add_item(store, action_iter, out binding_iter, "Window Floating Toggle", "<Super><Shift> f"); | ||
|
||
add_category(store, out action_iter, "Resize"); | ||
|
||
add_item(store, action_iter, out binding_iter, "Enter Resize Mode", "<Super> r"); | ||
add_item(store, action_iter, out binding_iter, "Resize Window", "↑ ↓ ← →"); | ||
add_item(store, action_iter, out binding_iter, "Resize Window", "k j h l"); | ||
add_item(store, action_iter, out binding_iter, "Exit Resize Mode", "Escape"); | ||
|
||
add_category(store, out action_iter, "Other"); | ||
|
||
add_item(store, action_iter, out binding_iter, "Kill Focused Window", "<Super><Shift> q"); | ||
add_item(store, action_iter, out binding_iter, "Lock Screen", "<Super> Escape"); | ||
add_item(store, action_iter, out binding_iter, "Logout", "<Super><Shift> e"); | ||
add_item(store, action_iter, out binding_iter, "Suspend Computer", "<Super><Shift> s"); | ||
add_item(store, action_iter, out binding_iter, "Reboot Computer", "<Super><Shift> b"); | ||
add_item(store, action_iter, out binding_iter, "Shutdown Computer", "<Super><Shift> p"); | ||
add_item(store, action_iter, out binding_iter, "Toogle this Dialog", "<Super><Shift> ?"); | ||
|
||
view.expand_all (); | ||
} | ||
|
||
private static void add_category(TreeStore store, out TreeIter iter, string label) { | ||
store.append (out iter, null); | ||
store.set (iter, 0, label, -1); | ||
} | ||
|
||
private static void add_item(TreeStore store, TreeIter parent_iter, out TreeIter iter, string action, string keybinding) { | ||
store.append (out iter, parent_iter); | ||
store.set (iter, 0, action, 1, keybinding, -1); | ||
} | ||
|
||
private static void style_window(Gtk.Window window) { | ||
window.set_skip_taskbar_hint(true); | ||
window.set_skip_pager_hint(true); | ||
window.set_decorated(true); | ||
window.set_resizable(false); | ||
window.set_focus_on_map(false); | ||
window.set_deletable(false); | ||
window.set_accept_focus(false); | ||
window.set_type_hint(SPLASHSCREEN); | ||
window.stick(); | ||
} | ||
} | ||
} |