DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 1 | // |
| 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 | |
| 40 | extern void fl_fix_focus(); // in Fl.cxx |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 41 | void fl_update_focus(void); |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 42 | |
| 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. |
| 47 | extern HWND fl_capture; |
| 48 | #endif |
| 49 | |
| 50 | #ifdef __APPLE__ |
| 51 | extern void *fl_capture; |
| 52 | #endif |
| 53 | |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 54 | #if !(defined(WIN32) || defined(__APPLE__)) |
| 55 | extern int ewmh_supported(); // from Fl_x.cxx |
| 56 | #endif |
| 57 | |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 58 | void Fl::grab(Fl_Window* win) { |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 59 | 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 | |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 67 | 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 |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 76 | Window xid = fullscreen_win ? fl_xid(fullscreen_win) : fl_xid(first_window()); |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 77 | XGrabPointer(fl_display, |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 78 | xid, |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 79 | 1, |
| 80 | ButtonPressMask|ButtonReleaseMask| |
| 81 | ButtonMotionMask|PointerMotionMask, |
| 82 | GrabModeAsync, |
| 83 | GrabModeAsync, |
| 84 | None, |
| 85 | 0, |
| 86 | fl_event_time); |
| 87 | XGrabKeyboard(fl_display, |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 88 | xid, |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 89 | 1, |
| 90 | GrabModeAsync, |
| 91 | GrabModeAsync, |
| 92 | fl_event_time); |
| 93 | #endif |
| 94 | } |
| 95 | grab_ = win; |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 96 | fl_update_focus(); |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 97 | } else { |
| 98 | if (grab_) { |
| 99 | #ifdef WIN32 |
| 100 | fl_capture = 0; |
| 101 | ReleaseCapture(); |
| 102 | #elif defined(__APPLE__) |
| 103 | fl_capture = 0; |
| 104 | #else |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 105 | // We must keep the grab in the non-EWMH fullscreen case |
| 106 | if (!fullscreen_win || ewmh_supported()) { |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 107 | XUngrabKeyboard(fl_display, fl_event_time); |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 108 | } |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 109 | 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; |
DRC | 685f17e | 2011-07-28 09:23:00 +0000 | [diff] [blame] | 115 | fl_update_focus(); |
DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 116 | fl_fix_focus(); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // |
| 122 | // End of "$Id: Fl_grab.cxx 8055 2010-12-18 22:31:01Z manolo $". |
| 123 | // |