diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-15 18:35:58 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-15 18:35:58 +0100 |
commit | 37650d71d32f4f5ac9fcd09a37e4a5a991a5a66a (patch) | |
tree | fe0afca7c5f609f465b076598be9d8df8c912c6a /src/utilities | |
parent | 6edfb34cb3eee958e392a433ae9ac4f240279d09 (diff) |
Imported Upstream version 0.5.6
Diffstat (limited to 'src/utilities')
-rw-r--r-- | src/utilities/bindingManager.vala | 126 | ||||
-rw-r--r-- | src/utilities/paths.vala | 136 |
2 files changed, 131 insertions, 131 deletions
diff --git a/src/utilities/bindingManager.vala b/src/utilities/bindingManager.vala index 255dbfb..0c74ece 100644 --- a/src/utilities/bindingManager.vala +++ b/src/utilities/bindingManager.vala @@ -17,8 +17,8 @@ this program. If not, see <http://www.gnu.org/licenses/>. namespace GnomePie { -///////////////////////////////////////////////////////////////////////// -/// Globally binds key stroke to given ID's. When one of the bound +///////////////////////////////////////////////////////////////////////// +/// Globally binds key stroke to given ID's. When one of the bound /// strokes is invoked, a signal with the according ID is emitted. ///////////////////////////////////////////////////////////////////////// @@ -30,61 +30,61 @@ public class BindingManager : GLib.Object { ///////////////////////////////////////////////////////////////////// public signal void on_press(string id); - + ///////////////////////////////////////////////////////////////////// /// A list storing bindings, which are invoked even if Gnome-Pie /// doesn't have the current focus ///////////////////////////////////////////////////////////////////// - + private Gee.List<Keybinding> bindings = new Gee.ArrayList<Keybinding>(); ///////////////////////////////////////////////////////////////////// /// Ignored modifier masks, used to grab all keys even if these locks /// are active. ///////////////////////////////////////////////////////////////////// - + private static uint[] lock_modifiers = { 0, Gdk.ModifierType.MOD2_MASK, Gdk.ModifierType.LOCK_MASK, Gdk.ModifierType.MOD5_MASK, - + Gdk.ModifierType.MOD2_MASK|Gdk.ModifierType.LOCK_MASK, Gdk.ModifierType.MOD2_MASK|Gdk.ModifierType.MOD5_MASK, Gdk.ModifierType.LOCK_MASK|Gdk.ModifierType.MOD5_MASK, - + Gdk.ModifierType.MOD2_MASK|Gdk.ModifierType.LOCK_MASK|Gdk.ModifierType.MOD5_MASK }; - + ///////////////////////////////////////////////////////////////////// /// Some variables to remember which delayed binding was delayed. /// When the delay passes without another event indicating that the /// Trigger was released, the stored binding will be activated. ///////////////////////////////////////////////////////////////////// - + private uint32 delayed_count = 0; private X.Event? delayed_event = null; private Keybinding? delayed_binding = null; - + ///////////////////////////////////////////////////////////////////// /// Helper class to store keybinding ///////////////////////////////////////////////////////////////////// - + private class Keybinding { - + public Keybinding(Trigger trigger, string id) { this.trigger = trigger; this.id = id; } - + public Trigger trigger { get; set; } public string id { get; set; } } - + ///////////////////////////////////////////////////////////////////// /// C'tor adds the event filter to the root window. ///////////////////////////////////////////////////////////////////// - + public BindingManager() { // init filter to retrieve X.Events Gdk.Window rootwin = Gdk.get_default_root_window(); @@ -92,45 +92,45 @@ public class BindingManager : GLib.Object { rootwin.add_filter(event_filter); } } - + ///////////////////////////////////////////////////////////////////// /// Binds the ID to the given accelerator. ///////////////////////////////////////////////////////////////////// - + public void bind(Trigger trigger, string id) { if(trigger.key_code != 0) { - X.Display display = Gdk.x11_get_default_xdisplay(); - X.ID xid = Gdk.x11_get_default_root_xwindow(); - + X.Display display = Gdk.X11.get_default_xdisplay(); + X.ID xid = Gdk.X11.get_default_root_xwindow(); + Gdk.error_trap_push(); - + foreach(uint lock_modifier in lock_modifiers) { if (trigger.with_mouse) { display.grab_button(trigger.key_code, trigger.modifiers|lock_modifier, xid, false, - X.EventMask.ButtonPressMask | X.EventMask.ButtonReleaseMask, + X.EventMask.ButtonPressMask | X.EventMask.ButtonReleaseMask, X.GrabMode.Async, X.GrabMode.Async, xid, 0); } else { - display.grab_key(trigger.key_code, trigger.modifiers|lock_modifier, + display.grab_key(trigger.key_code, trigger.modifiers|lock_modifier, xid, false, X.GrabMode.Async, X.GrabMode.Async); } } - + Gdk.flush(); - + Keybinding binding = new Keybinding(trigger, id); bindings.add(binding); display.flush(); } } - + ///////////////////////////////////////////////////////////////////// /// Unbinds the accelerator of the given ID. ///////////////////////////////////////////////////////////////////// - + public void unbind(string id) { - X.Display display = Gdk.x11_get_default_xdisplay(); - X.ID xid = Gdk.x11_get_default_root_xwindow(); - + X.Display display = Gdk.X11.get_default_xdisplay(); + X.ID xid = Gdk.X11.get_default_root_xwindow(); + Gee.List<Keybinding> remove_bindings = new Gee.ArrayList<Keybinding>(); foreach(var binding in bindings) { if(id == binding.id) { @@ -139,7 +139,7 @@ public class BindingManager : GLib.Object { display.ungrab_button(binding.trigger.key_code, binding.trigger.modifiers|lock_modifier, xid); } else { display.ungrab_key(binding.trigger.key_code, binding.trigger.modifiers|lock_modifier, xid); - } + } } remove_bindings.add(binding); } @@ -148,68 +148,68 @@ public class BindingManager : GLib.Object { bindings.remove_all(remove_bindings); display.flush(); } - + ///////////////////////////////////////////////////////////////////// /// Returns a human readable accelerator for the given ID. ///////////////////////////////////////////////////////////////////// - + public string get_accelerator_label_of(string id) { foreach (var binding in bindings) { if (binding.id == id) { return binding.trigger.label_with_specials; } } - + return _("Not bound"); } - + ///////////////////////////////////////////////////////////////////// /// Returns the accelerator to which the given ID is bound. ///////////////////////////////////////////////////////////////////// - + public string get_accelerator_of(string id) { foreach (var binding in bindings) { if (binding.id == id) { return binding.trigger.name; } } - + return ""; } - + ///////////////////////////////////////////////////////////////////// /// Returns whether the pie with the given ID is in turbo mode. ///////////////////////////////////////////////////////////////////// - + public bool get_is_turbo(string id) { foreach (var binding in bindings) { if (binding.id == id) { return binding.trigger.turbo; } } - + return false; } - + ///////////////////////////////////////////////////////////////////// /// Returns whether the pie with the given ID opens centered. ///////////////////////////////////////////////////////////////////// - + public bool get_is_centered(string id) { foreach (var binding in bindings) { if (binding.id == id) { return binding.trigger.centered; } } - + return false; } - + ///////////////////////////////////////////////////////////////////// /// Returns the name ID of the Pie bound to the given Trigger. /// Returns "" if there is nothing bound to this trigger. ///////////////////////////////////////////////////////////////////// - + public string get_assigned_id(Trigger trigger) { foreach (var binding in bindings) { var first = binding.trigger.name.replace("[turbo]", "").replace("[delayed]", ""); @@ -218,23 +218,23 @@ public class BindingManager : GLib.Object { return binding.id; } } - + return ""; } ///////////////////////////////////////////////////////////////////// /// Event filter method needed to fetch X.Events. ///////////////////////////////////////////////////////////////////// - - private Gdk.FilterReturn event_filter(Gdk.XEvent gdk_xevent, Gdk.Event gdk_event) { - + + private Gdk.FilterReturn event_filter(Gdk.XEvent gdk_xevent, Gdk.Event gdk_event) { + #if VALA_0_16 || VALA_0_17 X.Event* xevent = (X.Event*) gdk_xevent; #else void* pointer = &gdk_xevent; X.Event* xevent = (X.Event*) pointer; #endif - + if(xevent->type == X.EventType.KeyPress) { foreach(var binding in bindings) { // remove NumLock, CapsLock and ScrollLock from key state @@ -247,7 +247,7 @@ public class BindingManager : GLib.Object { } } } - } + } else if(xevent->type == X.EventType.ButtonPress) { foreach(var binding in bindings) { // remove NumLock, CapsLock and ScrollLock from key state @@ -263,49 +263,49 @@ public class BindingManager : GLib.Object { } else if(xevent->type == X.EventType.ButtonRelease || xevent->type == X.EventType.KeyRelease) { this.activate_delayed(null, *xevent); - } - + } + return Gdk.FilterReturn.CONTINUE; } - + ///////////////////////////////////////////////////////////////////// /// This method is always called when a trigger is activated which is /// delayed. Therefore on_press() is only emitted, when this method /// is not called again within 300 milliseconds. Else a fake event is /// sent in order to simulate the actual key which has been pressed. ///////////////////////////////////////////////////////////////////// - + private void activate_delayed(Keybinding? binding , X.Event event) { // increase event count, so any waiting event will realize that // something happened in the meantime var current_count = ++this.delayed_count; - + if (binding == null && this.delayed_event != null) { // if the trigger is released and an event is currently waiting // simulate that the trigger has been pressed without any inter- // ference of Gnome-Pie - X.Display display = Gdk.x11_get_default_xdisplay(); - + X.Display display = Gdk.X11.get_default_xdisplay(); + // unbind the trigger, else we'll capture that event again ;) unbind(delayed_binding.id); - + if (this.delayed_binding.trigger.with_mouse) { // simulate mouse click X.Test.fake_button_event(display, this.delayed_event.xbutton.button, true, 0); display.flush(); - + X.Test.fake_button_event(display, this.delayed_event.xbutton.button, false, 0); display.flush(); - + } else { // simulate key press X.Test.fake_key_event(display, this.delayed_event.xkey.keycode, true, 0); display.flush(); - + X.Test.fake_key_event(display, this.delayed_event.xkey.keycode, false, 0); display.flush(); } - + // bind it again bind(delayed_binding.trigger, delayed_binding.id); } else if (binding != null) { diff --git a/src/utilities/paths.vala b/src/utilities/paths.vala index fe8897b..5b39c45 100644 --- a/src/utilities/paths.vala +++ b/src/utilities/paths.vala @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2011 by Simon Schneegans This program is free software: you can redistribute it and/or modify it @@ -12,12 +12,12 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. +this program. If not, see <http://www.gnu.org/licenses/>. */ namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A static class which stores all relevant paths used by Gnome-Pie. /// These depend upon the location from which the program was launched. ///////////////////////////////////////////////////////////////////////// @@ -28,122 +28,122 @@ public class Paths : GLib.Object { /// The config directory, /// usually ~/.config/gnome-pie/. ///////////////////////////////////////////////////////////////////// - + public static string config_directory { get; private set; default=""; } ///////////////////////////////////////////////////////////////////// /// The log file, /// usually ~/.config/gnome-pie/gnome-pie.log. ///////////////////////////////////////////////////////////////////// - + public static string log { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The statistics file, /// usually ~/.config/gnome-pie/gnome-pie.stats. ///////////////////////////////////////////////////////////////////// - + public static string stats { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The settings file, /// usually ~/.config/gnome-pie/gnome-pie.conf. ///////////////////////////////////////////////////////////////////// - + public static string settings { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The pie configuration file /// usually ~/.config/gnome-pie/pies.conf. ///////////////////////////////////////////////////////////////////// - + public static string pie_config { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The directory containing themes installed by the user /// usually ~/.config/gnome-pie/themes. ///////////////////////////////////////////////////////////////////// - + public static string local_themes { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The directory containing pre-installed themes /// usually /usr/share/gnome-pie/themes. ///////////////////////////////////////////////////////////////////// - + public static string global_themes { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The directory containing locale files /// usually /usr/share/locale. ///////////////////////////////////////////////////////////////////// - + public static string locales { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The directory containing UI declaration files /// usually /usr/share/gnome-pie/ui/. ///////////////////////////////////////////////////////////////////// - + public static string ui_files { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The autostart file of gnome-pie_config /// usually ~/.config/autostart/gnome-pie.desktop. ///////////////////////////////////////////////////////////////////// - + public static string autostart { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The path where all pie-launchers are stored /// usually ~/.config/gnome-pie/launchers. ///////////////////////////////////////////////////////////////////// - + public static string launchers { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// The path to the executable. ///////////////////////////////////////////////////////////////////// - + public static string executable { get; private set; default=""; } - + ///////////////////////////////////////////////////////////////////// /// Initializes all values above. ///////////////////////////////////////////////////////////////////// - + public static void init() { - + // get path of executable try { executable = GLib.File.new_for_path(GLib.FileUtils.read_link("/proc/self/exe")).get_path(); } catch (GLib.FileError e) { warning("Failed to get path of executable!"); } - + // append resources to icon search path to icon theme, if neccasary var icon_dir = GLib.File.new_for_path(GLib.Path.get_dirname(executable)).get_child("resources"); - + if (icon_dir.query_exists()) { string path = icon_dir.get_path(); Gtk.IconTheme.get_default().append_search_path(path); } - + Gtk.IconTheme.get_default().append_search_path("/usr/share/pixmaps/"); - + // get global paths var default_dir = GLib.File.new_for_path("/usr/share/gnome-pie/"); if(!default_dir.query_exists()) { default_dir = GLib.File.new_for_path("/usr/local/share/gnome-pie/"); - + if(!default_dir.query_exists()) { default_dir = GLib.File.new_for_path(GLib.Path.get_dirname( executable)).get_child("resources"); } } - + global_themes = default_dir.get_path() + "/themes"; ui_files = default_dir.get_path() + "/ui"; - + // get locales path var locale_dir = GLib.File.new_for_path("/usr/share/locale/de/LC_MESSAGES/gnomepie.mo"); if(locale_dir.query_exists()) { @@ -155,16 +155,16 @@ public class Paths : GLib.Object { } else { locale_dir = GLib.File.new_for_path(GLib.Path.get_dirname( executable)).get_child("resources/locale/de/LC_MESSAGES/gnomepie.mo"); - + if(locale_dir.query_exists()) { locale_dir = GLib.File.new_for_path(GLib.Path.get_dirname( executable)).get_child("resources/locale"); } } } - + locales = locale_dir.get_path(); - + // get local paths var config_dir = GLib.File.new_for_path( GLib.Environment.get_user_config_dir()).get_child("gnome-pie"); @@ -177,9 +177,9 @@ public class Paths : GLib.Object { error(e.message); } } - + config_directory = config_dir.get_path(); - + // create local themes directory if neccasary var themes_dir = config_dir.get_child("themes"); if(!themes_dir.query_exists()) { @@ -189,9 +189,9 @@ public class Paths : GLib.Object { error(e.message); } } - + local_themes = themes_dir.get_path(); - + // create launchers directory if neccasary var launchers_dir = config_dir.get_child("launchers"); if(!launchers_dir.query_exists()) { @@ -201,17 +201,17 @@ public class Paths : GLib.Object { error(e.message); } } - + launchers = launchers_dir.get_path(); - + // check for config file var config_file = config_dir.get_child("pies.conf"); - + pie_config = config_file.get_path(); settings = config_dir.get_path() + "/gnome-pie.conf"; log = config_dir.get_path() + "/gnome-pie.log"; stats = config_dir.get_path() + "/gnome-pie.stats"; - + if (!GLib.File.new_for_path(log).query_exists()) { try { FileUtils.set_contents(log, ""); @@ -219,7 +219,7 @@ public class Paths : GLib.Object { error(e.message); } } - + if (!GLib.File.new_for_path(stats).query_exists()) { try { FileUtils.set_contents(stats, ""); @@ -227,36 +227,36 @@ public class Paths : GLib.Object { error(e.message); } } - + // autostart file name - autostart = GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), + autostart = GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), "autostart", "gnome-pie.desktop", null); - + // print results - if (!GLib.File.new_for_path(pie_config).query_exists()) + if (!GLib.File.new_for_path(pie_config).query_exists()) warning("Failed to find pie configuration file \"pies.conf\"! (This should only happen when Gnome-Pie is started for the first time...)"); - - if (!GLib.File.new_for_path(settings).query_exists()) + + if (!GLib.File.new_for_path(settings).query_exists()) warning("Failed to find settings file \"gnome-pie.conf\"! (This should only happen when Gnome-Pie is started for the first time...)"); - - if (!GLib.File.new_for_path(log).query_exists()) + + if (!GLib.File.new_for_path(log).query_exists()) warning("Failed to find log file \"gnome-pie.log\"!"); - - if (!GLib.File.new_for_path(stats).query_exists()) + + if (!GLib.File.new_for_path(stats).query_exists()) warning("Failed to find statistics file \"gnome-pie.stats\"!"); - - if (!GLib.File.new_for_path(local_themes).query_exists()) + + if (!GLib.File.new_for_path(local_themes).query_exists()) warning("Failed to find local themes directory!"); - - if (!GLib.File.new_for_path(launchers).query_exists()) + + if (!GLib.File.new_for_path(launchers).query_exists()) warning("Failed to find launchers directory!"); - - if (!GLib.File.new_for_path(global_themes).query_exists()) - warning("Failed to find global themes directory!"); - - if (!GLib.File.new_for_path(ui_files).query_exists()) - warning("Failed to find UI files directory!"); - } + + if (!GLib.File.new_for_path(global_themes).query_exists()) + warning("Failed to find global themes directory!"); + + if (!GLib.File.new_for_path(ui_files).query_exists()) + warning("Failed to find UI files directory!"); + } } } |