1 | /* |
2 | * Copyright © 2016 Red Hat, Inc |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #include "config.h" |
19 | |
20 | #include <glib.h> |
21 | #include <gio/gio.h> |
22 | |
23 | #include "gdkmonitor-x11.h" |
24 | #include "gdkx11display.h" |
25 | #include "gdkdisplay-x11.h" |
26 | #include "gdkscreen-x11.h" |
27 | #include "gdkdisplayprivate.h" |
28 | #include "gdkprivate-x11.h" |
29 | |
30 | |
31 | G_DEFINE_TYPE (GdkX11Monitor, gdk_x11_monitor, GDK_TYPE_MONITOR) |
32 | |
33 | static gboolean |
34 | gdk_monitor_has_fullscreen_window (GdkMonitor *monitor) |
35 | { |
36 | GList *toplevels, *l; |
37 | GdkSurface *surface; |
38 | gboolean has_fullscreen; |
39 | |
40 | toplevels = gdk_x11_display_get_toplevel_windows (display: monitor->display); |
41 | |
42 | has_fullscreen = FALSE; |
43 | for (l = toplevels; l; l = l->next) |
44 | { |
45 | surface = l->data; |
46 | |
47 | if (!GDK_IS_TOPLEVEL (ptr: surface)) |
48 | continue; |
49 | |
50 | if ((gdk_toplevel_get_state (toplevel: GDK_TOPLEVEL (ptr: surface)) & GDK_TOPLEVEL_STATE_FULLSCREEN) == 0) |
51 | continue; |
52 | |
53 | if (surface->fullscreen_mode == GDK_FULLSCREEN_ON_ALL_MONITORS || |
54 | gdk_display_get_monitor_at_surface (display: monitor->display, surface) == monitor) |
55 | { |
56 | has_fullscreen = TRUE; |
57 | break; |
58 | } |
59 | } |
60 | |
61 | return has_fullscreen; |
62 | } |
63 | |
64 | /** |
65 | * gdk_x11_monitor_get_workarea: |
66 | * @monitor: (type GdkX11Monitor): a `GdkMonitor` |
67 | * @workarea: (out): a `GdkRectangle` to be filled with the monitor workarea |
68 | * |
69 | * Retrieves the size and position of the “work area” on a monitor |
70 | * within the display coordinate space. |
71 | * |
72 | * The returned geometry is in ”application pixels”, not in ”device pixels” |
73 | * (see [method@Gdk.Monitor.get_scale_factor]). |
74 | */ |
75 | void |
76 | gdk_x11_monitor_get_workarea (GdkMonitor *monitor, |
77 | GdkRectangle *dest) |
78 | { |
79 | GdkX11Screen *screen = GDK_X11_DISPLAY (monitor->display)->screen; |
80 | GdkRectangle workarea; |
81 | |
82 | gdk_monitor_get_geometry (monitor, geometry: dest); |
83 | |
84 | if (_gdk_x11_screen_get_monitor_work_area (screen, monitor, area: &workarea)) |
85 | { |
86 | if (!gdk_monitor_has_fullscreen_window (monitor)) |
87 | *dest = workarea; |
88 | } |
89 | else |
90 | { |
91 | /* The EWMH constrains workarea to be a rectangle, so it |
92 | * can't adequately deal with L-shaped monitor arrangements. |
93 | * As a workaround, we ignore the workarea for anything |
94 | * but the primary monitor. Since that is where the 'desktop |
95 | * chrome' usually lives, this works ok in practice. |
96 | */ |
97 | if (monitor == gdk_x11_display_get_primary_monitor (display: monitor->display) && |
98 | !gdk_monitor_has_fullscreen_window (monitor)) |
99 | { |
100 | gdk_x11_screen_get_work_area (screen, area: &workarea); |
101 | if (gdk_rectangle_intersect (src1: dest, src2: &workarea, dest: &workarea)) |
102 | *dest = workarea; |
103 | } |
104 | } |
105 | } |
106 | |
107 | static void |
108 | gdk_x11_monitor_init (GdkX11Monitor *monitor) |
109 | { |
110 | } |
111 | |
112 | static void |
113 | gdk_x11_monitor_class_init (GdkX11MonitorClass *class) |
114 | { |
115 | } |
116 | |
117 | /** |
118 | * gdk_x11_monitor_get_output: |
119 | * @monitor: (type GdkX11Monitor): a `GdkMonitor` |
120 | * |
121 | * Returns the XID of the Output corresponding to @monitor. |
122 | * |
123 | * Returns: the XID of @monitor |
124 | */ |
125 | XID |
126 | gdk_x11_monitor_get_output (GdkMonitor *monitor) |
127 | { |
128 | g_return_val_if_fail (GDK_IS_X11_MONITOR (monitor), 0); |
129 | |
130 | return GDK_X11_MONITOR (monitor)->output; |
131 | } |
132 | |
133 | |