diff --git a/Makefile b/Makefile index 6457e96..9c618ed 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ BINDIR = bin # for most cases the following two are the only you'll need to change # add your source files here -SRC = main.vala neo-window.vala key-overlay.vala tray.vala config-manager.vala keybinding-manager.vala keysend.c checkModifier.c +SRC = src/main.vala src/neo-window.vala src/key-overlay.vala src/tray.vala src/config-manager.vala src/keybinding-manager.vala csrc/keysend.c csrc/checkModifier.c # add your used packges here PKGS = --pkg x11 --pkg keysym --pkg gtk+-2.0 --pkg gee-1.0 --pkg gdk-x11-2.0 --pkg posix @@ -22,7 +22,9 @@ VAPIDIR = --vapi=vapi/keysym.vapi # compiler options for a debug build #VALACOPTS = -g --save-temps -VALACOPTS = +VALAC_DEBUG_OPTS = +# compiler options for a debug build +VALAC_RELEASE_OPTS = -X -O2 --disable-assert # set this as root makefile for Valencia BUILD_ROOT = 1 @@ -40,10 +42,10 @@ $(BINDIR): ln -s ../assets bin/assets bulid_debug: - @$(VALAC) $(VAPIDIR) $(VALACOPTS) $(SRC) -o $(BINDIR)/$(PROGRAM) $(PKGS) $(CC_INCLUDES) + @$(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o $(BINDIR)/$(PROGRAM) $(PKGS) $(CC_INCLUDES) bulid_release: - @$(VALAC) -X -O2 $(VAPIDIR) $(SRC) -o $(BINDIR)/$(PROGRAM)_release $(PKGS) $(CC_INCLUDES) + @$(VALAC) $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) -o $(BINDIR)/$(PROGRAM)_release $(PKGS) $(CC_INCLUDES) # clean all built files clean: diff --git a/checkModifier.c b/csrc/checkModifier.c similarity index 100% rename from checkModifier.c rename to csrc/checkModifier.c diff --git a/keysend.c b/csrc/keysend.c similarity index 100% rename from keysend.c rename to csrc/keysend.c diff --git a/keysend.h b/csrc/keysend.h similarity index 100% rename from keysend.h rename to csrc/keysend.h diff --git a/config-manager.vala b/src/config-manager.vala similarity index 96% rename from config-manager.vala rename to src/config-manager.vala index 62dfd29..a92be34 100644 --- a/config-manager.vala +++ b/src/config-manager.vala @@ -1,6 +1,6 @@ namespace NeoLayoutViewer{ - class ConfigManager { + public class ConfigManager { public Gee.HashMap config; private Gee.HashMap description;// allow optional commenting config entrys. @@ -38,8 +38,8 @@ namespace NeoLayoutViewer{ Standard values. This vaules will be written in the config file if no config file found. */ public void add_defaults(){ - //config.set("show_shortcut","N", "Toggle the visibility of the window."); - addSetting("show_shortcut","Q", "Toggle the visibility of the window."); + //config.set("show_shortcut","n", "Toggle the visibility of the window."); + addSetting("show_shortcut","q", "Toggle the visibility of the window."); addSetting("on_top","1", "Show window on top."); addSetting("position","3", "Window position on startup (num pad orientation)"); addSetting("width","1000","With in Pixel. Min_width and max_width bound sensible values. ");//Skalierung, sofern wert zwischen width(resolution)*max_width und width(resolution)*min_width diff --git a/key-overlay.vala b/src/key-overlay.vala similarity index 99% rename from key-overlay.vala rename to src/key-overlay.vala index 89947ee..df19eef 100644 --- a/key-overlay.vala +++ b/src/key-overlay.vala @@ -321,7 +321,7 @@ namespace NeoLayoutViewer{ int posX = 0; int posY = 0; - GLib.stdout.printf(@"$winWidthUnscaled , $width , $scaleX\n"); + //GLib.stdout.printf(@"$winWidthUnscaled , $width , $scaleX\n"); //++ Top row ++ scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 49, false, winMain, hboxes[0], 0); @@ -584,7 +584,7 @@ namespace NeoLayoutViewer{ this.all(winMain, width, height); this.keysym = keysym; - GLib.stdout.printf("Ww: %i, Wh: %i\n", width, height); + //GLib.stdout.printf("Ww: %i, Wh: %i\n", width, height); this.button_press_event.connect ((event) => { uint ks = this.keysym[this.layer_permutation[winMain.ebene]-1]; @@ -654,7 +654,7 @@ namespace NeoLayoutViewer{ requisition.width = width ;// / Pango.SCALE; requisition.height = height; // / Pango.SCALE; - GLib.stdout.printf("W: %i, H: %i, Sc: %f\n",width, height, Pango.SCALE); + //GLib.stdout.printf("W: %i, H: %i, Sc: %f\n",width, height, Pango.SCALE); } diff --git a/keybinding-manager.vala b/src/keybinding-manager.vala similarity index 54% rename from keybinding-manager.vala rename to src/keybinding-manager.vala index 22d4c96..4dde256 100644 --- a/keybinding-manager.vala +++ b/src/keybinding-manager.vala @@ -15,7 +15,6 @@ namespace NeoLayoutViewer{ * list of binded keybindings */ private Gee.List bindings = new Gee.ArrayList(); - private Gee.List modifier_bindings = new Gee.ArrayList(); /** * locked modifiers used to grab all keys whatever lock key * is pressed. @@ -55,29 +54,6 @@ namespace NeoLayoutViewer{ public KeybindingHandlerFunc handler { get; set; } } - - /** - * Helper class to store second set of keybindings (modifier) - */ - private class ModifierKeybinding - { - public ModifierKeybinding(string accelerator, int keycode, - Gdk.ModifierType modifiers, int ebene, KeybindingHandlerFunc handler) - { - this.accelerator = accelerator; - this.keycode = keycode; - this.ebene = ebene; - this.modifiers = modifiers; - this.handler = handler; - } - - public string accelerator { get; set; } - public int keycode { get; set; } - public int ebene { get; set; } - public Gdk.ModifierType modifiers { get; set; } - public KeybindingHandlerFunc handler { get; set; } - } - /** * Keybinding func needed to bind key to handler * @@ -107,15 +83,6 @@ namespace NeoLayoutViewer{ modifier_keycodes[8] = display->keysym_to_keycode(XK_Alt_L); modifier_keycodes[9] = display->keysym_to_keycode(XK_Alt_R); - //some tests - /* - X.Display display = Gdk.x11_drawable_get_xdisplay(rootwin); - X.ModifierKeymap modmap = display->get_modifier_mapping (); - debug("Max mod: %i\n".printf(modmap.max_keypermod)); - for(int i=0; ikeysym_to_keycode(keysym); if(keycode != 0) { @@ -159,44 +122,10 @@ namespace NeoLayoutViewer{ Keybinding binding = new Keybinding(accelerator, keycode, modifiers, handler); bindings.add(binding); - //debug("Successfully binded key " + accelerator); + debug("Successfully binded key " + accelerator); } } - - public void bind2(int keycode, string accelerator, int ebene, KeybindingHandlerFunc handler) - { - - // convert accelerator - /*uint keysym; - Gdk.ModifierType modifiers; - Gtk.accelerator_parse(accelerator, out keysym, out modifiers);*/ - - //Gdk.Window rootwin = Gdk.get_default_root_window(); - //unowned X.Display display = Gdk.x11_drawable_get_xdisplay(rootwin); - //X.ID xid = Gdk.x11_drawable_get_xid(rootwin); - //int keycode = display->keysym_to_keycode(keysym); - - if(keycode != 0) { - // trap XErrors to avoid closing of application - // even when grabing of key fails - Gdk.error_trap_push(); - - // grab key finally - display->grab_key(keycode, 0, xid, true, X.GrabMode.Async, X.GrabMode.Async); - - // wait until all X request have been processed - Gdk.flush(); - - // store binding - ModifierKeybinding binding = new ModifierKeybinding(accelerator, keycode, 0, ebene, handler); - modifier_bindings.add(binding); - - //debug("Successfully binded key "); - } - } - - /** * Unbind given accelerator. * @@ -205,7 +134,7 @@ namespace NeoLayoutViewer{ public void unbind(string accelerator) { - //debug("Unbinding key " + accelerator); + debug("Unbinding key " + accelerator); //Gdk.Window rootwin = Gdk.get_default_root_window(); //unowned X.Display display = Gdk.x11_drawable_get_xdisplay(rootwin); @@ -223,31 +152,11 @@ namespace NeoLayoutViewer{ } // remove unbinded keys bindings.remove_all(remove_bindings); + + debug("Successfully unbinded key " + accelerator); } - public void unbind2(int keycode) - { - //debug("Unbinding key\n "); - - //Gdk.Window rootwin = Gdk.get_default_root_window(); - //unowned X.Display display = Gdk.x11_drawable_get_xdisplay(rootwin); - //X.ID xid = Gdk.x11_drawable_get_xid(rootwin); - - // unbind all keys with given accelerator - Gee.List remove_bindings = new Gee.ArrayList(); - foreach(ModifierKeybinding binding in modifier_bindings) { - if(keycode == binding.keycode) { - display->ungrab_key(binding.keycode, binding.modifiers, xid); - remove_bindings.add(binding); - } - } - // remove unbinded keys - bindings.remove_all(remove_bindings); - } - - - /** * Event filter method needed to fetch X.Events */ @@ -270,72 +179,12 @@ namespace NeoLayoutViewer{ } } - if(xevent->type == X.EventType.KeyPress) { - //uint event_mods = xevent.xkey.state; - foreach(ModifierKeybinding binding in modifier_bindings) { - if(xevent->xkey.keycode == binding.keycode) { - //neo_win.external_key_press(binding.ebene,(int)event_mods); - neo_win.active_modifier_by_keyboard[binding.ebene] = 1; - neo_win.redraw(); - // call all handlers with pressed key and modifiers - binding.handler(gdk_event); - send_event_again(Gdk.get_default_root_window(), xevent, binding); - } - } - } - - if(xevent->type == X.EventType.KeyRelease) { - //uint event_mods = xevent.xkey.state; - foreach(ModifierKeybinding binding in modifier_bindings) { - if(xevent->xkey.keycode == binding.keycode) { - //neo_win.external_key_release(0,(int)event_mods); - neo_win.active_modifier_by_keyboard[binding.ebene] = 0; - neo_win.redraw(); - // call all handlers with pressed key and modifiers - binding.handler(gdk_event); - send_event_again(Gdk.get_default_root_window(), xevent, binding); - } - } - } - - - debug("Filter %u\n".printf(xevent.xkey.keycode)); - - //send_event_again(Gdk.get_default_root_window(), *xevent, binding); - return filter_return; } - - private void send_event_again(Gdk.Window rootwin, X.Event* xevent, ModifierKeybinding binding){ - - //X.ID xid = Gdk.x11_drawable_get_xid(rootwin); - - display->ungrab_key(binding.keycode, binding.modifiers, xid); - //modifier_timeout_store.add(binding); - //putBack(display, xevent); - //display->grab_key(binding.keycode, 0, xid, false, X.GrabMode.Async, X.GrabMode.Async); - - /* - if(rootwin != null) { - unowned X.Display display = Gdk.x11_drawable_get_xdisplay(rootwin); - X.ID xid = Gdk.x11_drawable_get_xid(rootwin); - foreach(ModifierKeybinding binding in modifier_bindings){ - display->ungrab_key(binding.keycode, binding.modifiers, xid); - } - - //rootwin.remove_filter(event_filter); - debug("Send Event again %u\n".printf(xevent.xkey.state)); - display->send_event(xevent.xkey.window,true,xevent.xkey.state,ref xevent); - //rootwin.add_filter(event_filter); - - foreach(ModifierKeybinding binding in modifier_bindings){ - // display->grab_key(binding.keycode, 0, xid, false, X.GrabMode.Async, X.GrabMode.Async); - } - } - */ - } - + /* + Checks periodical which modifier are pressed. + */ private bool modifier_timer(){ if(rootwin == null) { debug("Root window changed."); @@ -345,7 +194,6 @@ namespace NeoLayoutViewer{ xid = Gdk.x11_drawable_get_xid(rootwin); } - //debug("check Modifier"); checkModifier(display,&modifier_keycodes[0], modifier_keycodes.length, &modifier_pressed[0]); // Convert modifier keys to modifier/layer @@ -359,16 +207,9 @@ namespace NeoLayoutViewer{ // stdout.printf(@"Mods: $(neo_win.active_modifier[1]), $(neo_win.active_modifier[2]), $(neo_win.active_modifier[3])\n" ); neo_win.redraw(); - if(true) return true; - /* - foreach(ModifierKeybinding binding in modifier_timeout_store) { - display->grab_key(binding.keycode, 0, xid, true, X.GrabMode.Async, X.GrabMode.Async); - debug("Timer"); - } - modifier_timeout_store.clear(); - - return true; - */ + return true; } - } -} + }// End KeybindingManager class + + +}// End Namespace diff --git a/main.vala b/src/main.vala similarity index 100% rename from main.vala rename to src/main.vala diff --git a/neo-window.vala b/src/neo-window.vala similarity index 100% rename from neo-window.vala rename to src/neo-window.vala diff --git a/tray.vala b/src/tray.vala similarity index 98% rename from tray.vala rename to src/tray.vala index 9d0c5a6..f1d4cb9 100644 --- a/tray.vala +++ b/src/tray.vala @@ -2,7 +2,7 @@ using Gtk; namespace NeoLayoutViewer{ - class AppStatusIcon { + public class AppStatusIcon { public StatusIcon trayicon; private Menu menuMain; private NeoWindow neo_win; diff --git a/vapi/keysym.vapi b/vapi/keysym.vapi index 96ebc12..1a40e97 100644 --- a/vapi/keysym.vapi +++ b/vapi/keysym.vapi @@ -2,7 +2,20 @@ [CCode (cprefix = "NeoLayoutViewer", lower_case_cprefix = "neo_layout_viewer_")] namespace NeoLayoutViewer { - [CCode (cheader_filename = "main.h")] + [CCode (ref_function = "neo_layout_viewer_app_status_icon_ref", unref_function = "neo_layout_viewer_app_status_icon_unref", cheader_filename = "src/main.h")] + public class AppStatusIcon { + public Gtk.StatusIcon trayicon; + public AppStatusIcon (NeoLayoutViewer.NeoWindow neo_win); + public void create_menuMain (); + } + [CCode (ref_function = "neo_layout_viewer_config_manager_ref", unref_function = "neo_layout_viewer_config_manager_unref", cheader_filename = "src/main.h")] + public class ConfigManager { + public Gee.HashMap config; + public ConfigManager (string conffile); + public void add_defaults (); + public Gee.HashMap getConfig (); + } + [CCode (cheader_filename = "src/main.h")] public class KeyEventBox : Gtk.EventBox { public KeyEventBox (NeoLayoutViewer.NeoWindow winMain, int width, int height, ref uint[] keysym); public KeyEventBox.freeArea (NeoLayoutViewer.NeoWindow winMain, int width, int height); @@ -10,7 +23,7 @@ namespace NeoLayoutViewer { public KeyEventBox.modifier2 (NeoLayoutViewer.NeoWindow winMain, int width, int height, int modifier_index); public override void size_request (out Gtk.Requisition requisition); } - [CCode (cheader_filename = "main.h")] + [CCode (cheader_filename = "src/main.h")] public class KeyOverlay : Gtk.VBox { public Gee.HashMap keyBoxes; public Gee.HashMap keysyms; @@ -18,18 +31,16 @@ namespace NeoLayoutViewer { public void generateKeyevents (); public Gee.HashMap generateKeysyms (); } - [CCode (cheader_filename = "main.h")] + [CCode (cheader_filename = "src/main.h")] public class KeybindingManager : GLib.Object { - [CCode (cheader_filename = "main.h")] + [CCode (cheader_filename = "src/main.h")] public delegate void KeybindingHandlerFunc (Gdk.Event event); public KeybindingManager (NeoLayoutViewer.NeoWindow neo_win); public void bind (string accelerator, NeoLayoutViewer.KeybindingManager.KeybindingHandlerFunc handler); - public void bind2 (int keycode, string accelerator, int ebene, NeoLayoutViewer.KeybindingManager.KeybindingHandlerFunc handler); public Gdk.FilterReturn event_filter (Gdk.XEvent gdk_xevent, Gdk.Event gdk_event); public void unbind (string accelerator); - public void unbind2 (int keycode); } - [CCode (cheader_filename = "main.h")] + [CCode (cheader_filename = "src/main.h")] public class NeoWindow : Gtk.Window { public int[] MODIFIER_MASK; public int[] NEO_MODIFIER_MASK; @@ -55,6 +66,14 @@ namespace NeoLayoutViewer { public override void show_all (); public bool toggle (); } - [CCode (cheader_filename = "main.h")] + [CCode (cheader_filename = "src/main.h")] + public static NeoLayoutViewer.ConfigManager configm; + [CCode (cheader_filename = "src/main.h")] + public static NeoLayoutViewer.KeybindingManager manager; + [CCode (cheader_filename = "src/main.h")] + public static NeoLayoutViewer.AppStatusIcon neo_tray; + [CCode (cheader_filename = "src/main.h")] + public static NeoLayoutViewer.NeoWindow neo_win; + [CCode (cheader_filename = "src/main.h")] public static int main (string[] args); }