Guest User

Untitled

a guest
Oct 30th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.58 KB | None | 0 0
  1.     /* Code from Gnome-Do */
  2.     public static void present_window (Gtk.Window window)
  3.     {
  4.       // raise without grab
  5.       uint32 timestamp = Gtk.get_current_event_time();
  6.       window.present_with_time (timestamp);
  7.       window.get_window ().raise ();
  8.       window.get_window ().focus (timestamp);
  9.  
  10.       if (Synapse.Utils.Logger.debug_enabled ()) return;
  11.       // grab
  12.       int i = 0;
  13.       Timeout.add (100, ()=>{
  14.         if (i >= 100)
  15.           return false;
  16.         ++i;
  17.         return !try_grab_window (window);
  18.       });
  19.     }
  20.     /* Code from Gnome-Do */
  21.     public static void unpresent_window (Gtk.Window window)
  22.     {
  23.       if (Synapse.Utils.Logger.debug_enabled ()) return;
  24.       uint32 time = Gtk.get_current_event_time();
  25.  
  26.       Gdk.pointer_ungrab (time);
  27.       Gdk.keyboard_ungrab (time);
  28.       Gtk.grab_remove (window);
  29.     }
  30.     /* Code from Gnome-Do */
  31.     private static bool try_grab_window (Gtk.Window window)
  32.     {
  33.       uint time = Gtk.get_current_event_time();
  34.       if (Gdk.pointer_grab (window.get_window(),
  35.             true,
  36.             Gdk.EventMask.BUTTON_PRESS_MASK |
  37.             Gdk.EventMask.BUTTON_RELEASE_MASK |
  38.             Gdk.EventMask.POINTER_MOTION_MASK,
  39.             null,
  40.             null,
  41.             time) == Gdk.GrabStatus.SUCCESS)
  42.       {
  43.         if (Gdk.keyboard_grab (window.get_window(), true, time) == Gdk.GrabStatus.SUCCESS) {
  44.           Gtk.grab_add (window);
  45.           return true;
  46.         } else {
  47.           Gdk.pointer_ungrab (time);
  48.           return false;
  49.         }
  50.       }
  51.       return false;
  52.     }
  53.  
  54.   }
Add Comment
Please, Sign In to add comment