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 | |
Pierre Ossman | b808ffd | 2012-09-11 11:12:56 +0000 | [diff] [blame^] | 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 23 | #include <FL/Fl.H> |
| 24 | #include <FL/Fl_Window.H> |
| 25 | #include <FL/x.H> |
| 26 | |
| 27 | #import <Cocoa/Cocoa.h> |
| 28 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 29 | static bool captured = false; |
| 30 | |
Pierre Ossman | 3d75911 | 2012-08-27 14:40:51 +0000 | [diff] [blame] | 31 | int cocoa_capture_display(Fl_Window *win, bool all_displays) |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 32 | { |
| 33 | NSWindow *nsw; |
| 34 | |
| 35 | nsw = (NSWindow*)fl_xid(win); |
| 36 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 37 | if (!captured) { |
Pierre Ossman | 3d75911 | 2012-08-27 14:40:51 +0000 | [diff] [blame] | 38 | if (all_displays) { |
| 39 | if (CGCaptureAllDisplays() != kCGErrorSuccess) |
| 40 | return 1; |
| 41 | } else { |
| 42 | CGDirectDisplayID displays[16]; |
| 43 | CGDisplayCount count; |
| 44 | int index; |
| 45 | |
| 46 | if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess) |
| 47 | return 1; |
| 48 | |
| 49 | if (count != Fl::screen_count()) |
| 50 | return 1; |
| 51 | |
| 52 | #ifdef HAVE_FLTK_FULLSCREEN_SCREENS |
| 53 | index = Fl::screen_num(win->x(), win->y(), win->w(), win->h()); |
| 54 | #else |
| 55 | index = 0; |
| 56 | #endif |
| 57 | |
| 58 | if (CGDisplayCapture(displays[index]) != kCGErrorSuccess) |
| 59 | return 1; |
| 60 | } |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 61 | |
| 62 | captured = true; |
| 63 | } |
| 64 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 65 | if ([nsw level] == CGShieldingWindowLevel()) |
| 66 | return 0; |
| 67 | |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 68 | [nsw setLevel:CGShieldingWindowLevel()]; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | void cocoa_release_display(Fl_Window *win) |
| 74 | { |
| 75 | NSWindow *nsw; |
| 76 | int newlevel; |
| 77 | |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 78 | if (captured) |
Pierre Ossman | 3d75911 | 2012-08-27 14:40:51 +0000 | [diff] [blame] | 79 | CGReleaseAllDisplays(); |
Pierre Ossman | a4f0f18 | 2011-06-14 13:36:57 +0000 | [diff] [blame] | 80 | |
| 81 | captured = false; |
Pierre Ossman | 407a5c3 | 2011-05-26 14:48:29 +0000 | [diff] [blame] | 82 | |
| 83 | nsw = (NSWindow*)fl_xid(win); |
| 84 | |
| 85 | // Someone else has already changed the level of this window |
| 86 | if ([nsw level] != CGShieldingWindowLevel()) |
| 87 | return; |
| 88 | |
| 89 | // FIXME: Store the previous level somewhere so we don't have to hard |
| 90 | // code a level here. |
| 91 | #ifdef HAVE_FLTK_FULLSCREEN |
| 92 | if (win->fullscreen_active() && win->contains(Fl::focus())) |
| 93 | newlevel = NSStatusWindowLevel; |
| 94 | else |
| 95 | #endif |
| 96 | newlevel = NSNormalWindowLevel; |
| 97 | |
| 98 | // Only change if different as the level change also moves the window |
| 99 | // to the top of that level. |
| 100 | if ([nsw level] != newlevel) |
| 101 | [nsw setLevel:newlevel]; |
| 102 | } |