Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 1 | /* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #include <FL/Fl.H> |
| 20 | #include <FL/Fl_Window.H> |
| 21 | #include <FL/x.H> |
| 22 | |
| 23 | #import <Cocoa/Cocoa.h> |
| 24 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame^] | 25 | static bool captured = false; |
| 26 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 27 | int cocoa_capture_display(Fl_Window *win) |
| 28 | { |
| 29 | NSWindow *nsw; |
| 30 | |
| 31 | nsw = (NSWindow*)fl_xid(win); |
| 32 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame^] | 33 | if (!captured) { |
| 34 | if (CGDisplayCapture(kCGDirectMainDisplay) != kCGErrorSuccess) |
| 35 | return 1; |
| 36 | |
| 37 | captured = true; |
| 38 | } |
| 39 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 40 | if ([nsw level] == CGShieldingWindowLevel()) |
| 41 | return 0; |
| 42 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 43 | [nsw setLevel:CGShieldingWindowLevel()]; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | void cocoa_release_display(Fl_Window *win) |
| 49 | { |
| 50 | NSWindow *nsw; |
| 51 | int newlevel; |
| 52 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame^] | 53 | if (captured) |
| 54 | CGDisplayRelease(kCGDirectMainDisplay); |
| 55 | |
| 56 | captured = false; |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 57 | |
| 58 | nsw = (NSWindow*)fl_xid(win); |
| 59 | |
| 60 | // Someone else has already changed the level of this window |
| 61 | if ([nsw level] != CGShieldingWindowLevel()) |
| 62 | return; |
| 63 | |
| 64 | // FIXME: Store the previous level somewhere so we don't have to hard |
| 65 | // code a level here. |
| 66 | #ifdef HAVE_FLTK_FULLSCREEN |
| 67 | if (win->fullscreen_active() && win->contains(Fl::focus())) |
| 68 | newlevel = NSStatusWindowLevel; |
| 69 | else |
| 70 | #endif |
| 71 | newlevel = NSNormalWindowLevel; |
| 72 | |
| 73 | // Only change if different as the level change also moves the window |
| 74 | // to the top of that level. |
| 75 | if ([nsw level] != newlevel) |
| 76 | [nsw setLevel:newlevel]; |
| 77 | } |