Re: Grabs on Win32 (Was: [Gimp-developer] Screenshot plug-in status)



Tor Lillqvist writes:
 > Something more closely resembling X11 grabbing might be possible using
 > so-called hooks. I have no experience (so far) with using hooks... but
 > the API doesn't look difficult. I'll check what one can do with
 > them. 

It looks as if global hooks could, in theory, well be used to
implement pointer and keyboard grab semantics that would closely mimic
those on X11.

But: Implementing global hooks correctly is quite complicated. A
global hook is set up with SetWindowsHookEx() to call a procedure,
which must be in a DLL. (That's OK, that DLL would be the GDK
DLL. I.e. one more reason why GDK should always be built as a DLL on
Win3.) That DLL is (automatically) attached to every current and
future process that has windows on the desktop.

Now comes the hard part: The hook procedure is called in the context
of each process. I.e. the (data) address space it sees is that of each
process, not that of the process that called gdk_pointer_grab(). No
way can it use any data that is present in the process than called
gdk_pointer_grab(). One would have to use shared memory, named mutexes
and events, and whatnot to be able to generate the GdkEvents resulting
from the grab in the GDK instance in the original processes.

Is it worth it? Probably not. As far as I can see, GTK works
reasonably well on Win32 even if the exact semantics of pointer and
keyboard grabs are far from those on X11. There are more important
things to fix first (like GDK use from multiple threads).

Also, the PSDK docs say:

  Note: You should use global hooks only for debugging purposes;
  otherwise, you should avoid them. Global hooks hurt system
  performance and cause conflicts with other applications that
  implement the same type of global hook.

which kinda suggests to me that it would not be a good idea to set and
unset global hooks for things like pointer grabs, which GTK seems to
use quite often.

Comments, please?

--tml





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]