blob: 38724bdd537bf263f2df201cc579872b4302f726 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_grab.cxx 8055 2010-12-18 22:31:01Z manolo $"
3//
4// Grab/release code for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28#include <config.h>
29#include <FL/Fl.H>
30#include <FL/x.H>
31
32////////////////////////////////////////////////////////////////
33// "Grab" is done while menu systems are up. This has several effects:
34// Events are all sent to the "grab window", which does not even
35// have to be displayed (and in the case of Fl_Menu.cxx it isn't).
36// The system is also told to "grab" events and send them to this app.
37// This also modifies how Fl_Window::show() works, on X it turns on
38// override_redirect, it does similar things on WIN32.
39
40extern void fl_fix_focus(); // in Fl.cxx
DRC685f17e2011-07-28 09:23:00 +000041void fl_update_focus(void);
DRC2ff39b82011-07-28 08:38:59 +000042
43#ifdef WIN32
44// We have to keep track of whether we have captured the mouse, since
45// MSWindows shows little respect for this... Grep for fl_capture to
46// see where and how this is used.
47extern HWND fl_capture;
48#endif
49
50#ifdef __APPLE__
51extern void *fl_capture;
52#endif
53
DRC685f17e2011-07-28 09:23:00 +000054#if !(defined(WIN32) || defined(__APPLE__))
55extern int ewmh_supported(); // from Fl_x.cxx
56#endif
57
DRC2ff39b82011-07-28 08:38:59 +000058void Fl::grab(Fl_Window* win) {
DRC685f17e2011-07-28 09:23:00 +000059 Fl_Window *fullscreen_win = NULL;
60 for (Fl_Window *W = Fl::first_window(); W; W = Fl::next_window(W)) {
61 if (W->fullscreen_active()) {
62 fullscreen_win = W;
63 break;
64 }
65 }
66
DRC2ff39b82011-07-28 08:38:59 +000067 if (win) {
68 if (!grab_) {
69#ifdef WIN32
70 SetActiveWindow(fl_capture = fl_xid(first_window()));
71 SetCapture(fl_capture);
72#elif defined(__APPLE__)
73 fl_capture = Fl_X::i(first_window())->xid;
74 Fl_X::i(first_window())->set_key_window();
75#else
DRC685f17e2011-07-28 09:23:00 +000076 Window xid = fullscreen_win ? fl_xid(fullscreen_win) : fl_xid(first_window());
DRC2ff39b82011-07-28 08:38:59 +000077 XGrabPointer(fl_display,
DRC685f17e2011-07-28 09:23:00 +000078 xid,
DRC2ff39b82011-07-28 08:38:59 +000079 1,
80 ButtonPressMask|ButtonReleaseMask|
81 ButtonMotionMask|PointerMotionMask,
82 GrabModeAsync,
83 GrabModeAsync,
84 None,
85 0,
86 fl_event_time);
87 XGrabKeyboard(fl_display,
DRC685f17e2011-07-28 09:23:00 +000088 xid,
DRC2ff39b82011-07-28 08:38:59 +000089 1,
90 GrabModeAsync,
91 GrabModeAsync,
92 fl_event_time);
93#endif
94 }
95 grab_ = win;
DRC685f17e2011-07-28 09:23:00 +000096 fl_update_focus();
DRC2ff39b82011-07-28 08:38:59 +000097 } else {
98 if (grab_) {
99#ifdef WIN32
100 fl_capture = 0;
101 ReleaseCapture();
102#elif defined(__APPLE__)
103 fl_capture = 0;
104#else
DRC685f17e2011-07-28 09:23:00 +0000105 // We must keep the grab in the non-EWMH fullscreen case
106 if (!fullscreen_win || ewmh_supported()) {
DRC2ff39b82011-07-28 08:38:59 +0000107 XUngrabKeyboard(fl_display, fl_event_time);
DRC685f17e2011-07-28 09:23:00 +0000108 }
DRC2ff39b82011-07-28 08:38:59 +0000109 XUngrabPointer(fl_display, fl_event_time);
110 // this flush is done in case the picked menu item goes into
111 // an infinite loop, so we don't leave the X server locked up:
112 XFlush(fl_display);
113#endif
114 grab_ = 0;
DRC685f17e2011-07-28 09:23:00 +0000115 fl_update_focus();
DRC2ff39b82011-07-28 08:38:59 +0000116 fl_fix_focus();
117 }
118 }
119}
120
121//
122// End of "$Id: Fl_grab.cxx 8055 2010-12-18 22:31:01Z manolo $".
123//