blob: 589da2d93447328cb98416ee88423577cbee1c61 [file] [log] [blame]
Pierre Ossman407a5c32011-05-26 14:48:29 +00001/* 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
25int cocoa_capture_display(Fl_Window *win)
26{
27 NSWindow *nsw;
28
29 nsw = (NSWindow*)fl_xid(win);
30
31 // Already captured?
32 if ([nsw level] == CGShieldingWindowLevel())
33 return 0;
34
35 if (CGDisplayCapture(kCGDirectMainDisplay) != kCGErrorSuccess)
36 return 1;
37
38 [nsw setLevel:CGShieldingWindowLevel()];
39
40 return 0;
41}
42
43void cocoa_release_display(Fl_Window *win)
44{
45 NSWindow *nsw;
46 int newlevel;
47
48 CGDisplayRelease(kCGDirectMainDisplay);
49
50 nsw = (NSWindow*)fl_xid(win);
51
52 // Someone else has already changed the level of this window
53 if ([nsw level] != CGShieldingWindowLevel())
54 return;
55
56 // FIXME: Store the previous level somewhere so we don't have to hard
57 // code a level here.
58#ifdef HAVE_FLTK_FULLSCREEN
59 if (win->fullscreen_active() && win->contains(Fl::focus()))
60 newlevel = NSStatusWindowLevel;
61 else
62#endif
63 newlevel = NSNormalWindowLevel;
64
65 // Only change if different as the level change also moves the window
66 // to the top of that level.
67 if ([nsw level] != newlevel)
68 [nsw setLevel:newlevel];
69}