diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-24 11:03:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-24 11:03:06 +0100 |
commit | b683ce2789d95b2e9f221e75adc30efd91cfb901 (patch) | |
tree | 7903b95887c3fbb995ec2e6a99b027053e617adf /src/utilities/focusGrabber.vala | |
parent | 73201cab74e84e5372b6c4a1f72f7e70df5c0d5a (diff) |
Imported Upstream version 0.5.7upstream/0.5.7
Diffstat (limited to 'src/utilities/focusGrabber.vala')
-rw-r--r-- | src/utilities/focusGrabber.vala | 120 |
1 files changed, 43 insertions, 77 deletions
diff --git a/src/utilities/focusGrabber.vala b/src/utilities/focusGrabber.vala index e5900d6..b551def 100644 --- a/src/utilities/focusGrabber.vala +++ b/src/utilities/focusGrabber.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 { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// Some helper methods which focus the input on a given Gtk.Window. ///////////////////////////////////////////////////////////////////////// @@ -27,7 +27,7 @@ public class FocusGrabber : GLib.Object { /// Utilities for grabbing focus. /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + public static void grab(Gdk.Window window, bool keyboard = true, bool pointer = true, bool owner_events = true) { if (keyboard || pointer) { window.raise(); @@ -42,90 +42,56 @@ public class FocusGrabber : GLib.Object { } } } - + ///////////////////////////////////////////////////////////////////// /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + public static void ungrab(bool keyboard = true, bool pointer = true) { - #if HAVE_GTK_3 - - var display = Gdk.Display.get_default(); - var manager = display.get_device_manager(); - - #if VALA_0_16 || VALA_0_17 - GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #else - unowned GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #endif - - foreach(var device in list) { - if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) - || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) - - device.ungrab(Gdk.CURRENT_TIME); - } - - #else - - if (pointer) Gdk.pointer_ungrab(Gdk.CURRENT_TIME); - if (keyboard) Gdk.keyboard_ungrab(Gdk.CURRENT_TIME); - - #endif + var display = Gdk.Display.get_default(); + var manager = display.get_device_manager(); + + GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); + + foreach(var device in list) { + if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) + || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) + + device.ungrab(Gdk.CURRENT_TIME); + } } - + ///////////////////////////////////////////////////////////////////// /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + private static bool try_grab_window(Gdk.Window window, bool keyboard, bool pointer, bool owner_events) { - #if HAVE_GTK_3 - - var display = Gdk.Display.get_default(); - var manager = display.get_device_manager(); - - bool grabbed_all = true; - - #if VALA_0_16 - GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #else - unowned GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #endif - - foreach(var device in list) { - if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) - || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) { - - var status = device.grab(window, Gdk.GrabOwnership.APPLICATION, owner_events, - Gdk.EventMask.ALL_EVENTS_MASK, null, Gdk.CURRENT_TIME); - - if (status != Gdk.GrabStatus.SUCCESS) - grabbed_all = false; - } - } - - if (grabbed_all) - return true; - - ungrab(keyboard, pointer); - - #else - - if (!pointer || Gdk.pointer_grab(window, owner_events, Gdk.EventMask.BUTTON_PRESS_MASK | - Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK, - null, null, Gdk.CURRENT_TIME) == Gdk.GrabStatus.SUCCESS) { - - if (!keyboard || Gdk.keyboard_grab(window, owner_events, Gdk.CURRENT_TIME) == Gdk.GrabStatus.SUCCESS) { - return true; - } else if (pointer) { - ungrab(false, true); - return false; - } + var display = Gdk.Display.get_default(); + var manager = display.get_device_manager(); + + bool grabbed_all = true; + + GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); + + foreach(var device in list) { + if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) + || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) { + + var status = device.grab(window, Gdk.GrabOwnership.APPLICATION, owner_events, + Gdk.EventMask.ALL_EVENTS_MASK, null, Gdk.CURRENT_TIME); + + if (status != Gdk.GrabStatus.SUCCESS) + grabbed_all = false; } - #endif - + } + + if (grabbed_all) + return true; + + ungrab(keyboard, pointer); + return false; - } + } } } |