summaryrefslogtreecommitdiff
path: root/src/utilities/bindingManager.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-04-18 15:42:59 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-04-18 15:42:59 +0200
commit84a27086bbd9f493128b354300f9c77ccb32a56b (patch)
tree977cb323f0ac6953f10bc20d84f45ebd5a6d4535 /src/utilities/bindingManager.vala
parentb683ce2789d95b2e9f221e75adc30efd91cfb901 (diff)
Imported Upstream version 0.6.0upstream/0.6.0
Diffstat (limited to 'src/utilities/bindingManager.vala')
-rw-r--r--src/utilities/bindingManager.vala153
1 files changed, 108 insertions, 45 deletions
diff --git a/src/utilities/bindingManager.vala b/src/utilities/bindingManager.vala
index 0c74ece..e90fa74 100644
--- a/src/utilities/bindingManager.vala
+++ b/src/utilities/bindingManager.vala
@@ -1,19 +1,19 @@
-/*
-Copyright (c) 2011 by Simon Schneegans
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the Free
-Software Foundation, either version 3 of the License, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-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/>.
-*/
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or 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/>.
+/////////////////////////////////////////////////////////////////////////
namespace GnomePie {
@@ -98,7 +98,7 @@ public class BindingManager : GLib.Object {
/////////////////////////////////////////////////////////////////////
public void bind(Trigger trigger, string id) {
- if(trigger.key_code != 0) {
+ if (trigger.key_code != 0) {
X.Display display = Gdk.X11.get_default_xdisplay();
X.ID xid = Gdk.X11.get_default_root_xwindow();
@@ -116,10 +116,13 @@ public class BindingManager : GLib.Object {
}
Gdk.flush();
-
Keybinding binding = new Keybinding(trigger, id);
bindings.add(binding);
display.flush();
+ } else {
+ //no key_code: just add the bindind to the list to save optional trigger parameters
+ Keybinding binding = new Keybinding(trigger, id);
+ bindings.add(binding);
}
}
@@ -128,6 +131,17 @@ public class BindingManager : GLib.Object {
/////////////////////////////////////////////////////////////////////
public void unbind(string id) {
+ foreach (var binding in bindings) {
+ if (id == binding.id) {
+ if (binding.trigger.key_code == 0) {
+ //no key_code: just remove the bindind from the list
+ bindings.remove(binding);
+ return;
+ }
+ break;
+ }
+ }
+
X.Display display = Gdk.X11.get_default_xdisplay();
X.ID xid = Gdk.X11.get_default_root_xwindow();
@@ -206,14 +220,59 @@ public class BindingManager : GLib.Object {
}
/////////////////////////////////////////////////////////////////////
+ /// Returns whether the pie with the given ID is in warp mode.
+ /////////////////////////////////////////////////////////////////////
+
+ public bool get_is_warp(string id) {
+ foreach (var binding in bindings) {
+ if (binding.id == id) {
+ return binding.trigger.warp;
+ }
+ }
+
+ return false;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns whether the pie with the given ID is auto shaped
+ /////////////////////////////////////////////////////////////////////
+
+ public bool get_is_auto_shape(string id) {
+ foreach (var binding in bindings) {
+ if (binding.id == id) {
+ return (binding.trigger.shape == 0);
+ }
+ }
+
+ return false;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns the prefered pie shape number
+ /////////////////////////////////////////////////////////////////////
+
+ public int get_shape_number(string id) {
+ foreach (var binding in bindings) {
+ if (binding.id == id) {
+ if (binding.trigger.shape == 0)
+ break; //return default if auto-shaped
+ return binding.trigger.shape; //use selected shape
+ }
+ }
+
+ return 5; //default= full pie
+ }
+
+
+ /////////////////////////////////////////////////////////////////////
/// 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]", "");
- var second = trigger.name.replace("[turbo]", "").replace("[delayed]", "");
+ var first = Trigger.remove_optional(binding.trigger.name);
+ var second = Trigger.remove_optional(trigger.name);
if (first == second) {
return binding.id;
}
@@ -276,48 +335,52 @@ public class BindingManager : GLib.Object {
/////////////////////////////////////////////////////////////////////
private void activate_delayed(Keybinding? binding , X.Event event) {
- // increase event count, so any waiting event will realize that
- // something happened in the meantime
+ // 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();
+ // 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();
- // unbind the trigger, else we'll capture that event again ;)
- unbind(delayed_binding.id);
+ // 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();
+ 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();
+ 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();
+ } 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();
- }
+ 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);
+
+ this.delayed_binding = null;
+ this.delayed_event = null;
+
} else if (binding != null) {
- // if the trigger has been pressed, store it and wait for any interuption
- // within the next 300 milliseconds
+ // if the trigger has been pressed, store it and wait for any interuption
+ // within the next 300 milliseconds
this.delayed_event = event;
this.delayed_binding = binding;
Timeout.add(300, () => {
- // if nothing has been pressed in the meantime
+ // if nothing has been pressed in the meantime
if (current_count == this.delayed_count) {
- this.delayed_binding = null;
+ this.delayed_binding = null;
this.delayed_event = null;
on_press(binding.id);
}