1 | /* |
---|
2 | * multiscreen-stuff: Xinerama (and in the future multidisplay) |
---|
3 | * support for the panel |
---|
4 | * |
---|
5 | * Copyright (C) 2001 George Lebl <jirka@5z.com> |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License as |
---|
9 | * published by the Free Software Foundation; either version 2 of the |
---|
10 | * License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
20 | * USA |
---|
21 | */ |
---|
22 | |
---|
23 | #include <config.h> |
---|
24 | #include <gnome.h> |
---|
25 | |
---|
26 | #include "panel-include.h" |
---|
27 | #include "foobar-widget.h" |
---|
28 | |
---|
29 | #include <X11/X.h> |
---|
30 | #include <X11/Xlib.h> |
---|
31 | #include <gdk/gdkx.h> |
---|
32 | #ifdef HAVE_LIBXINERAMA |
---|
33 | #include <X11/extensions/Xinerama.h> |
---|
34 | #endif |
---|
35 | |
---|
36 | #include "multiscreen-stuff.h" |
---|
37 | |
---|
38 | /* some globals */ |
---|
39 | static int screens = 1; |
---|
40 | static GdkRectangle * rectangles = NULL; |
---|
41 | static gboolean initialized = FALSE; |
---|
42 | |
---|
43 | void |
---|
44 | multiscreen_init (void) |
---|
45 | { |
---|
46 | #ifdef HAVE_LIBXINERAMA |
---|
47 | gboolean have_xinerama = FALSE; |
---|
48 | #endif |
---|
49 | |
---|
50 | if (initialized) |
---|
51 | return; |
---|
52 | |
---|
53 | if (g_getenv ("FAKE_XINERAMA_PANEL") != NULL) { |
---|
54 | /* fake xinerama setup for debugging */ |
---|
55 | screens = 2; |
---|
56 | rectangles = g_new0 (GdkRectangle, 2); |
---|
57 | rectangles[1].x = 0; |
---|
58 | rectangles[1].y = 0; |
---|
59 | rectangles[1].width = gdk_screen_width () / 2; |
---|
60 | rectangles[1].height = gdk_screen_height () / 2; |
---|
61 | rectangles[0].x = gdk_screen_width () / 2; |
---|
62 | rectangles[0].y = gdk_screen_height () / 2; |
---|
63 | rectangles[0].width = gdk_screen_width () - rectangles[0].x; |
---|
64 | rectangles[0].height = gdk_screen_height () - rectangles[0].y; |
---|
65 | |
---|
66 | initialized = TRUE; |
---|
67 | |
---|
68 | return; |
---|
69 | } |
---|
70 | |
---|
71 | #ifdef HAVE_LIBXINERAMA |
---|
72 | gdk_flush (); |
---|
73 | gdk_error_trap_push (); |
---|
74 | have_xinerama = XineramaIsActive (GDK_DISPLAY ()); |
---|
75 | gdk_flush (); |
---|
76 | if (gdk_error_trap_pop () != 0) |
---|
77 | have_xinerama = FALSE; |
---|
78 | |
---|
79 | if (have_xinerama) { |
---|
80 | int screen_num, i; |
---|
81 | XineramaScreenInfo *xscreens = |
---|
82 | XineramaQueryScreens (GDK_DISPLAY (), |
---|
83 | &screen_num); |
---|
84 | |
---|
85 | |
---|
86 | if (screen_num <= 0) { |
---|
87 | /* EEEEEK!, should never happen */ |
---|
88 | goto no_xinerama; |
---|
89 | } |
---|
90 | |
---|
91 | rectangles = g_new0 (GdkRectangle, screen_num); |
---|
92 | screens = screen_num; |
---|
93 | |
---|
94 | for (i = 0; i < screen_num; i++) { |
---|
95 | rectangles[i].x = xscreens[i].x_org; |
---|
96 | rectangles[i].y = xscreens[i].y_org; |
---|
97 | rectangles[i].width = xscreens[i].width; |
---|
98 | rectangles[i].height = xscreens[i].height; |
---|
99 | } |
---|
100 | |
---|
101 | XFree (xscreens); |
---|
102 | } else |
---|
103 | #endif |
---|
104 | { |
---|
105 | #ifdef HAVE_LIBXINERAMA |
---|
106 | no_xinerama: |
---|
107 | #endif |
---|
108 | /* no xinerama */ |
---|
109 | screens = 1; |
---|
110 | rectangles = g_new0 (GdkRectangle, 1); |
---|
111 | rectangles[0].x = 0; |
---|
112 | rectangles[0].y = 0; |
---|
113 | rectangles[0].width = gdk_screen_width (); |
---|
114 | rectangles[0].height = gdk_screen_height (); |
---|
115 | } |
---|
116 | |
---|
117 | initialized = TRUE; |
---|
118 | } |
---|
119 | |
---|
120 | int |
---|
121 | multiscreen_screens (void) |
---|
122 | { |
---|
123 | g_return_val_if_fail (initialized, 1); |
---|
124 | |
---|
125 | return screens; |
---|
126 | } |
---|
127 | |
---|
128 | int |
---|
129 | multiscreen_x (int screen) |
---|
130 | { |
---|
131 | g_return_val_if_fail (initialized, 0); |
---|
132 | g_return_val_if_fail (screen >= 0, 0); |
---|
133 | |
---|
134 | if (screen < screens) |
---|
135 | return rectangles[screen].x; |
---|
136 | else |
---|
137 | return gdk_screen_width () + 10; |
---|
138 | } |
---|
139 | |
---|
140 | int |
---|
141 | multiscreen_y (int screen) |
---|
142 | { |
---|
143 | g_return_val_if_fail (initialized, 0); |
---|
144 | g_return_val_if_fail (screen >= 0, 0); |
---|
145 | |
---|
146 | if (screen < screens) |
---|
147 | return rectangles[screen].y; |
---|
148 | else |
---|
149 | return gdk_screen_height () + 10; |
---|
150 | } |
---|
151 | |
---|
152 | int |
---|
153 | multiscreen_width (int screen) |
---|
154 | { |
---|
155 | g_return_val_if_fail (initialized, 0); |
---|
156 | g_return_val_if_fail (screen >= 0, 0); |
---|
157 | |
---|
158 | if (screen < screens) |
---|
159 | return rectangles[screen].width; |
---|
160 | else |
---|
161 | return gdk_screen_width (); |
---|
162 | } |
---|
163 | |
---|
164 | int |
---|
165 | multiscreen_height (int screen) |
---|
166 | { |
---|
167 | g_return_val_if_fail (initialized, 0); |
---|
168 | g_return_val_if_fail (screen >= 0, 0); |
---|
169 | |
---|
170 | if (screen < screens) |
---|
171 | return rectangles[screen].height; |
---|
172 | else |
---|
173 | return gdk_screen_height (); |
---|
174 | } |
---|
175 | |
---|
176 | int |
---|
177 | multiscreen_screen_from_pos (int x, int y) |
---|
178 | { |
---|
179 | int i; |
---|
180 | for (i = 0; i < screens; i++) { |
---|
181 | if (x >= rectangles[i].x && |
---|
182 | x <= rectangles[i].x + rectangles[i].width && |
---|
183 | y >= rectangles[i].y && |
---|
184 | y <= rectangles[i].y + rectangles[i].height) |
---|
185 | return i; |
---|
186 | } |
---|
187 | return -1; |
---|
188 | } |
---|
189 | |
---|
190 | int |
---|
191 | multiscreen_screen_from_panel (GtkWidget *widget) |
---|
192 | { |
---|
193 | g_return_val_if_fail (widget != NULL, 0); |
---|
194 | g_return_val_if_fail (IS_BASEP_WIDGET (widget) || |
---|
195 | IS_FOOBAR_WIDGET (widget), 0); |
---|
196 | |
---|
197 | if (IS_BASEP_WIDGET (widget)) |
---|
198 | return BASEP_WIDGET (widget)->screen; |
---|
199 | else if (IS_FOOBAR_WIDGET (widget)) |
---|
200 | return FOOBAR_WIDGET (widget)->screen; |
---|
201 | else |
---|
202 | return 0; |
---|
203 | } |
---|