Changeset 4b0895a574f8fbaaf2caa4a11fc9c6b4fe504c09

Show
Ignore:
Timestamp:
03/19/09 15:30:45 (3 years ago)
Author:
Lincoln de Sousa <lincoln@…>
Children:
014842639ffec88ea516166f1a40e612591a1d63
Parents:
c87d938e304a9095234a1e40819b25d5fd433bef
git-author:
Aleksandar Krsteski <alekrsteski@…> (03/18/09 21:03:28)
git-committer:
Lincoln de Sousa <lincoln@…> (03/19/09 15:30:45)
Message:

Try a better fix for losefocus race condition.

Try to fix the race condition between window losefocus event and
keybinding event from globalhotkeys in a better way, by comparing event
times of the keybinding event and losefocus event. To achive this add a
python binding for keybinder_get_current_event_time funcion and use it
to compare keybinding timestamp with losefocus timestamp.

Location:
src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/globalhotkeys/globalhotkeys.c

    r08770e8 r4b0895a5  
    197197} 
    198198 
     199static PyObject * 
     200GlobalHotkey_get_current_event_time (GlobalHotkey *self) 
     201{ 
     202  guint32 ret = keybinder_get_current_event_time (); 
     203  return Py_BuildValue ("i", ret); 
     204} 
     205 
    199206static struct PyMemberDef GlobalHotkey_members[] = { 
    200207  {"binded", T_OBJECT_EX, offsetof (GlobalHotkey, binded), 0, 
     
    216223  {"bind", (PyCFunction) GlobalHotkey_bind, 
    217224   METH_VARARGS, "Bind a key to a callable object"}, 
     225 
     226  {"get_current_event_time", (PyCFunction) GlobalHotkey_get_current_event_time, 
     227   METH_NOARGS, "Returns the timestamp of the current event"}, 
    218228 
    219229  {NULL}                        /* sentinel */ 
  • src/guake.py

    rc87d938 r4b0895a5  
    523523        self.fullscreen = False 
    524524 
     525        # holds the timestamp of the losefocus event 
     526        self.losefocus_time = 0 
     527 
    525528        # double click stuff 
    526529        def double_click(hbox, event): 
     
    605608        visible = window.get_property('visible') 
    606609        if value and visible and not self.showing_context_menu: 
     610            self.losefocus_time = gtk.gdk.x11_get_server_time(self.window.window) 
    607611            self.hide() 
    608  
    609             # There is a race condition between the focus-out-event and 
    610             # the global keybind that calls the self.show_hide method. I 
    611             # didn't investigate but this callback is allways called 
    612             # before the X keyboard event. So, to fix it temporarely, I 
    613             # did the following hammer: 
    614             def hack(): 
    615                 sleep(0.1) 
    616                 self.client.notify(GKEY('show_hide')) 
    617             self.hotkeys.unbind_all() 
    618             start_new_thread(hack, ()) 
    619612 
    620613    def show_menu(self, *args): 
     
    670663        """Toggles the main window visibility 
    671664        """ 
     665        event_time = self.hotkeys.get_current_event_time() 
     666 
     667        if self.losefocus_time and \ 
     668                self.losefocus_time >= event_time and \ 
     669                (self.losefocus_time - event_time) < 10: 
     670            self.losefocus_time = 0 
     671            return 
     672 
    672673        if not self.window.get_property('visible'): 
    673674            self.show()