| 1 |
/* |
| 2 |
* gdkscreen-x11.c |
| 3 |
* |
| 4 |
* Copyright 2001 Sun Microsystems Inc. |
| 5 |
* |
| 6 |
* Erwann Chenede <[email protected]> |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Library General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Library General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Library General Public |
| 19 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include "gdkscreen-x11.h" |
| 25 |
#include "gdkdisplay-x11.h" |
| 26 |
#include "gdkprivate-x11.h" |
| 27 |
#include "xsettings-client.h" |
| 28 |
#include "gdkmonitor-x11.h" |
| 29 |
|
| 30 |
#include <glib.h> |
| 31 |
|
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
#include <X11/Xatom.h> |
| 36 |
|
| 37 |
#ifdef HAVE_XFREE_XINERAMA |
| 38 |
#include <X11/extensions/Xinerama.h> |
| 39 |
#endif |
| 40 |
|
| 41 |
#ifdef HAVE_RANDR |
| 42 |
#include <X11/extensions/Xrandr.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifdef HAVE_XFIXES |
| 46 |
#include <X11/extensions/Xfixes.h> |
| 47 |
#endif |
| 48 |
|
| 49 |
static void gdk_x11_screen_dispose (GObject *object); |
| 50 |
static void gdk_x11_screen_finalize (GObject *object); |
| 51 |
static void init_randr_support (GdkScreen *screen); |
| 52 |
static void process_monitors_change (GdkScreen *screen); |
| 53 |
|
| 54 |
enum |
| 55 |
{ |
| 56 |
WINDOW_MANAGER_CHANGED, |
| 57 |
LAST_SIGNAL |
| 58 |
}; |
| 59 |
|
| 60 |
static guint signals[LAST_SIGNAL] = { 0 }; |
| 61 |
|
| 62 |
G_DEFINE_TYPE (GdkX11Screen, gdk_x11_screen, GDK_TYPE_SCREEN) |
| 63 |
|
| 64 |
typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms; |
| 65 |
|
| 66 |
struct _NetWmSupportedAtoms |
| 67 |
{ |
| 68 |
Atom *atoms; |
| 69 |
gulong n_atoms; |
| 70 |
}; |
| 71 |
|
| 72 |
static void |
| 73 |
gdk_x11_screen_init (GdkX11Screen *screen) |
| 74 |
{ |
| 75 |
} |
| 76 |
|
| 77 |
static GdkDisplay * |
| 78 |
gdk_x11_screen_get_display (GdkScreen *screen) |
| 79 |
{ |
| 80 |
return GDK_X11_SCREEN (screen)->display; |
| 81 |
} |
| 82 |
|
| 83 |
gint |
| 84 |
gdk_x11_screen_get_width (GdkScreen *screen) |
| 85 |
{ |
| 86 |
return GDK_X11_SCREEN (screen)->width; |
| 87 |
} |
| 88 |
|
| 89 |
gint |
| 90 |
gdk_x11_screen_get_height (GdkScreen *screen) |
| 91 |
{ |
| 92 |
return GDK_X11_SCREEN (screen)->height; |
| 93 |
} |
| 94 |
|
| 95 |
static gint |
| 96 |
gdk_x11_screen_get_width_mm (GdkScreen *screen) |
| 97 |
{ |
| 98 |
return WidthMMOfScreen (GDK_X11_SCREEN (screen)->xscreen); |
| 99 |
} |
| 100 |
|
| 101 |
static gint |
| 102 |
gdk_x11_screen_get_height_mm (GdkScreen *screen) |
| 103 |
{ |
| 104 |
return HeightMMOfScreen (GDK_X11_SCREEN (screen)->xscreen); |
| 105 |
} |
| 106 |
|
| 107 |
gint |
| 108 |
gdk_x11_screen_get_number (GdkScreen *screen) |
| 109 |
{ |
| 110 |
return GDK_X11_SCREEN (screen)->screen_num; |
| 111 |
} |
| 112 |
|
| 113 |
static GdkWindow * |
| 114 |
gdk_x11_screen_get_root_window (GdkScreen *screen) |
| 115 |
{ |
| 116 |
return GDK_X11_SCREEN (screen)->root_window; |
| 117 |
} |
| 118 |
|
| 119 |
static void |
| 120 |
gdk_x11_screen_dispose (GObject *object) |
| 121 |
{ |
| 122 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (object); |
| 123 |
int i; |
| 124 |
|
| 125 |
for (i = 0; i < 32; ++i) |
| 126 |
{ |
| 127 |
if (x11_screen->subwindow_gcs[i]) |
| 128 |
{ |
| 129 |
XFreeGC (x11_screen->xdisplay, x11_screen->subwindow_gcs[i]); |
| 130 |
x11_screen->subwindow_gcs[i] = 0; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
_gdk_x11_xsettings_finish (x11_screen); |
| 135 |
|
| 136 |
if (x11_screen->root_window) |
| 137 |
_gdk_window_destroy (x11_screen->root_window, TRUE); |
| 138 |
|
| 139 |
for (i = 0; i < x11_screen->nvisuals; i++) |
| 140 |
g_object_run_dispose (G_OBJECT (x11_screen->visuals[i])); |
| 141 |
|
| 142 |
G_OBJECT_CLASS (gdk_x11_screen_parent_class)->dispose (object); |
| 143 |
|
| 144 |
x11_screen->xdisplay = NULL; |
| 145 |
x11_screen->xscreen = NULL; |
| 146 |
x11_screen->screen_num = -1; |
| 147 |
x11_screen->xroot_window = None; |
| 148 |
x11_screen->wmspec_check_window = None; |
| 149 |
} |
| 150 |
|
| 151 |
static void |
| 152 |
gdk_x11_screen_finalize (GObject *object) |
| 153 |
{ |
| 154 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (object); |
| 155 |
gint i; |
| 156 |
|
| 157 |
if (x11_screen->root_window) |
| 158 |
g_object_unref (x11_screen->root_window); |
| 159 |
|
| 160 |
/* Visual Part */ |
| 161 |
for (i = 0; i < x11_screen->nvisuals; i++) |
| 162 |
g_object_unref (x11_screen->visuals[i]); |
| 163 |
g_free (x11_screen->visuals); |
| 164 |
g_hash_table_destroy (x11_screen->visual_hash); |
| 165 |
|
| 166 |
g_free (x11_screen->window_manager_name); |
| 167 |
|
| 168 |
G_OBJECT_CLASS (gdk_x11_screen_parent_class)->finalize (object); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* gdk_x11_screen_get_monitor_output: |
| 173 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 174 |
* @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen) |
| 175 |
* |
| 176 |
* Gets the XID of the specified output/monitor. |
| 177 |
* If the X server does not support version 1.2 of the RANDR |
| 178 |
* extension, 0 is returned. |
| 179 |
* |
| 180 |
* Returns: the XID of the monitor |
| 181 |
* |
| 182 |
* Since: 2.14 |
| 183 |
*/ |
| 184 |
XID |
| 185 |
gdk_x11_screen_get_monitor_output (GdkScreen *screen, |
| 186 |
gint monitor_num) |
| 187 |
{ |
| 188 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 189 |
GdkX11Display *x11_display = GDK_X11_DISPLAY (x11_screen->display); |
| 190 |
GdkX11Monitor *monitor; |
| 191 |
|
| 192 |
g_return_val_if_fail (GDK_IS_SCREEN (screen), None); |
| 193 |
g_return_val_if_fail (monitor_num >= 0, None); |
| 194 |
g_return_val_if_fail (monitor_num < x11_display->monitors->len, None); |
| 195 |
|
| 196 |
monitor = x11_display->monitors->pdata[monitor_num]; |
| 197 |
return monitor->output; |
| 198 |
} |
| 199 |
|
| 200 |
static int |
| 201 |
get_current_desktop (GdkScreen *screen) |
| 202 |
{ |
| 203 |
Display *display; |
| 204 |
Window win; |
| 205 |
Atom current_desktop, type; |
| 206 |
int format; |
| 207 |
unsigned long n_items, bytes_after; |
| 208 |
unsigned char *data_return = NULL; |
| 209 |
int workspace = 0; |
| 210 |
|
| 211 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, |
| 212 |
gdk_atom_intern_static_string ("_NET_CURRENT_DESKTOP"))) |
| 213 |
return workspace; |
| 214 |
|
| 215 |
display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); |
| 216 |
win = XRootWindow (display, GDK_SCREEN_XNUMBER (screen)); |
| 217 |
|
| 218 |
current_desktop = XInternAtom (display, "_NET_CURRENT_DESKTOP", True); |
| 219 |
|
| 220 |
XGetWindowProperty (display, |
| 221 |
win, |
| 222 |
current_desktop, |
| 223 |
0, G_MAXLONG, |
| 224 |
False, XA_CARDINAL, |
| 225 |
&type, &format, &n_items, &bytes_after, |
| 226 |
&data_return); |
| 227 |
|
| 228 |
if (type == XA_CARDINAL && format == 32 && n_items > 0) |
| 229 |
workspace = ((long *) data_return)[0]; |
| 230 |
|
| 231 |
if (data_return) |
| 232 |
XFree (data_return); |
| 233 |
|
| 234 |
return workspace; |
| 235 |
} |
| 236 |
|
| 237 |
gboolean |
| 238 |
_gdk_x11_screen_get_monitor_work_area (GdkScreen *screen, |
| 239 |
GdkMonitor *monitor, |
| 240 |
GdkRectangle *area) |
| 241 |
{ |
| 242 |
GdkX11Screen *x11_screen; |
| 243 |
GdkAtom net_workareas; |
| 244 |
GdkDisplay *display; |
| 245 |
Display *xdisplay; |
| 246 |
int current_desktop; |
| 247 |
char *workareas_dn_name; |
| 248 |
Atom workareas_dn; |
| 249 |
int screen_number; |
| 250 |
Window xroot; |
| 251 |
int result; |
| 252 |
Atom type; |
| 253 |
int format; |
| 254 |
gulong num; |
| 255 |
gulong leftovers; |
| 256 |
guchar *ret_workarea; |
| 257 |
long *workareas; |
| 258 |
GdkRectangle geometry; |
| 259 |
int i; |
| 260 |
|
| 261 |
x11_screen = GDK_X11_SCREEN (screen); |
| 262 |
|
| 263 |
net_workareas = gdk_atom_intern_static_string ("_GTK_WORKAREAS"); |
| 264 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, net_workareas)) |
| 265 |
return FALSE; |
| 266 |
|
| 267 |
display = gdk_screen_get_display (screen); |
| 268 |
xdisplay = gdk_x11_display_get_xdisplay (display); |
| 269 |
|
| 270 |
current_desktop = get_current_desktop (screen); |
| 271 |
workareas_dn_name = g_strdup_printf ("_GTK_WORKAREAS_D%d", current_desktop); |
| 272 |
workareas_dn = XInternAtom (xdisplay, workareas_dn_name, True); |
| 273 |
g_free (workareas_dn_name); |
| 274 |
|
| 275 |
if (workareas_dn == None) |
| 276 |
return FALSE; |
| 277 |
|
| 278 |
screen_number = gdk_x11_screen_get_screen_number (screen); |
| 279 |
xroot = XRootWindow (xdisplay, screen_number); |
| 280 |
|
| 281 |
gdk_x11_display_error_trap_push (display); |
| 282 |
|
| 283 |
ret_workarea = NULL; |
| 284 |
result = XGetWindowProperty (xdisplay, |
| 285 |
xroot, |
| 286 |
workareas_dn, |
| 287 |
0, |
| 288 |
G_MAXLONG, |
| 289 |
False, |
| 290 |
AnyPropertyType, |
| 291 |
&type, |
| 292 |
&format, |
| 293 |
&num, |
| 294 |
&leftovers, |
| 295 |
&ret_workarea); |
| 296 |
|
| 297 |
gdk_x11_display_error_trap_pop_ignored (display); |
| 298 |
|
| 299 |
if (result != Success || |
| 300 |
type == None || |
| 301 |
format == 0 || |
| 302 |
leftovers || |
| 303 |
num % 4 != 0) |
| 304 |
{ |
| 305 |
XFree (ret_workarea); |
| 306 |
|
| 307 |
return FALSE; |
| 308 |
} |
| 309 |
|
| 310 |
workareas = (long *) ret_workarea; |
| 311 |
|
| 312 |
gdk_monitor_get_geometry (monitor, &geometry); |
| 313 |
*area = geometry; |
| 314 |
|
| 315 |
for (i = 0; i < num / 4; i++) |
| 316 |
{ |
| 317 |
GdkRectangle work_area; |
| 318 |
|
| 319 |
work_area = (GdkRectangle) { |
| 320 |
.x = workareas[0] / x11_screen->window_scale, |
| 321 |
.y = workareas[1] / x11_screen->window_scale, |
| 322 |
.width = workareas[2] / x11_screen->window_scale, |
| 323 |
.height = workareas[3] / x11_screen->window_scale, |
| 324 |
}; |
| 325 |
|
| 326 |
if (gdk_rectangle_intersect (area, &work_area, &work_area)) |
| 327 |
*area = work_area; |
| 328 |
|
| 329 |
workareas += 4; |
| 330 |
} |
| 331 |
|
| 332 |
XFree (ret_workarea); |
| 333 |
|
| 334 |
return TRUE; |
| 335 |
} |
| 336 |
|
| 337 |
void |
| 338 |
gdk_x11_screen_get_work_area (GdkScreen *screen, |
| 339 |
GdkRectangle *area) |
| 340 |
{ |
| 341 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 342 |
Atom workarea; |
| 343 |
Atom type; |
| 344 |
Window win; |
| 345 |
int format; |
| 346 |
gulong num; |
| 347 |
gulong leftovers; |
| 348 |
gulong max_len = 4 * 32; |
| 349 |
guchar *ret_workarea = NULL; |
| 350 |
long *workareas; |
| 351 |
int result; |
| 352 |
int disp_screen; |
| 353 |
int desktop; |
| 354 |
Display *display; |
| 355 |
|
| 356 |
display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); |
| 357 |
disp_screen = GDK_SCREEN_XNUMBER (screen); |
| 358 |
workarea = XInternAtom (display, "_NET_WORKAREA", True); |
| 359 |
|
| 360 |
/* Defaults in case of error */ |
| 361 |
area->x = 0; |
| 362 |
area->y = 0; |
| 363 |
area->width = gdk_x11_screen_get_width (screen); |
| 364 |
area->height = gdk_x11_screen_get_height (screen); |
| 365 |
|
| 366 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, |
| 367 |
gdk_atom_intern_static_string ("_NET_WORKAREA"))) |
| 368 |
return; |
| 369 |
|
| 370 |
if (workarea == None) |
| 371 |
return; |
| 372 |
|
| 373 |
win = XRootWindow (display, disp_screen); |
| 374 |
result = XGetWindowProperty (display, |
| 375 |
win, |
| 376 |
workarea, |
| 377 |
0, |
| 378 |
max_len, |
| 379 |
False, |
| 380 |
AnyPropertyType, |
| 381 |
&type, |
| 382 |
&format, |
| 383 |
&num, |
| 384 |
&leftovers, |
| 385 |
&ret_workarea); |
| 386 |
if (result != Success || |
| 387 |
type == None || |
| 388 |
format == 0 || |
| 389 |
leftovers || |
| 390 |
num % 4 != 0) |
| 391 |
goto out; |
| 392 |
|
| 393 |
desktop = get_current_desktop (screen); |
| 394 |
if (desktop + 1 > num / 4) /* fvwm gets this wrong */ |
| 395 |
goto out; |
| 396 |
|
| 397 |
workareas = (long *) ret_workarea; |
| 398 |
area->x = workareas[desktop * 4]; |
| 399 |
area->y = workareas[desktop * 4 + 1]; |
| 400 |
area->width = workareas[desktop * 4 + 2]; |
| 401 |
area->height = workareas[desktop * 4 + 3]; |
| 402 |
|
| 403 |
area->x /= x11_screen->window_scale; |
| 404 |
area->y /= x11_screen->window_scale; |
| 405 |
area->width /= x11_screen->window_scale; |
| 406 |
area->height /= x11_screen->window_scale; |
| 407 |
|
| 408 |
out: |
| 409 |
if (ret_workarea) |
| 410 |
XFree (ret_workarea); |
| 411 |
} |
| 412 |
|
| 413 |
static GdkVisual * |
| 414 |
gdk_x11_screen_get_rgba_visual (GdkScreen *screen) |
| 415 |
{ |
| 416 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 417 |
|
| 418 |
return x11_screen->rgba_visual; |
| 419 |
} |
| 420 |
|
| 421 |
/** |
| 422 |
* gdk_x11_screen_get_xscreen: |
| 423 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 424 |
* |
| 425 |
* Returns the screen of a #GdkScreen. |
| 426 |
* |
| 427 |
* Returns: (transfer none): an Xlib Screen* |
| 428 |
* |
| 429 |
* Since: 2.2 |
| 430 |
*/ |
| 431 |
Screen * |
| 432 |
gdk_x11_screen_get_xscreen (GdkScreen *screen) |
| 433 |
{ |
| 434 |
return GDK_X11_SCREEN (screen)->xscreen; |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* gdk_x11_screen_get_screen_number: |
| 439 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 440 |
* |
| 441 |
* Returns the index of a #GdkScreen. |
| 442 |
* |
| 443 |
* Returns: the position of @screen among the screens |
| 444 |
* of its display |
| 445 |
* |
| 446 |
* Since: 2.2 |
| 447 |
*/ |
| 448 |
int |
| 449 |
gdk_x11_screen_get_screen_number (GdkScreen *screen) |
| 450 |
{ |
| 451 |
return GDK_X11_SCREEN (screen)->screen_num; |
| 452 |
} |
| 453 |
|
| 454 |
static Atom |
| 455 |
get_cm_atom (GdkX11Screen *x11_screen) |
| 456 |
{ |
| 457 |
return _gdk_x11_get_xatom_for_display_printf (x11_screen->display, "_NET_WM_CM_S%d", x11_screen->screen_num); |
| 458 |
} |
| 459 |
|
| 460 |
static gboolean |
| 461 |
check_is_composited (GdkDisplay *display, |
| 462 |
GdkX11Screen *x11_screen) |
| 463 |
{ |
| 464 |
Window xwindow; |
| 465 |
|
| 466 |
xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), get_cm_atom (x11_screen)); |
| 467 |
|
| 468 |
return xwindow != None; |
| 469 |
} |
| 470 |
|
| 471 |
static GdkX11Monitor * |
| 472 |
find_monitor_by_name (GdkX11Display *x11_display, |
| 473 |
char *name) |
| 474 |
{ |
| 475 |
int i; |
| 476 |
|
| 477 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 478 |
{ |
| 479 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 480 |
if (g_strcmp0 (monitor->name, name) == 0) |
| 481 |
return monitor; |
| 482 |
} |
| 483 |
|
| 484 |
return NULL; |
| 485 |
} |
| 486 |
|
| 487 |
static GdkSubpixelLayout |
| 488 |
translate_subpixel_order (int subpixel) |
| 489 |
{ |
| 490 |
switch (subpixel) |
| 491 |
{ |
| 492 |
case 1: return GDK_SUBPIXEL_LAYOUT_HORIZONTAL_RGB; |
| 493 |
case 2: return GDK_SUBPIXEL_LAYOUT_HORIZONTAL_BGR; |
| 494 |
case 3: return GDK_SUBPIXEL_LAYOUT_VERTICAL_RGB; |
| 495 |
case 4: return GDK_SUBPIXEL_LAYOUT_VERTICAL_BGR; |
| 496 |
case 5: return GDK_SUBPIXEL_LAYOUT_NONE; |
| 497 |
default: return GDK_SUBPIXEL_LAYOUT_UNKNOWN; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
static gboolean |
| 502 |
init_randr15 (GdkScreen *screen, gboolean *changed) |
| 503 |
{ |
| 504 |
#ifdef HAVE_RANDR15 |
| 505 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 506 |
GdkX11Display *x11_display = GDK_X11_DISPLAY (display); |
| 507 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 508 |
XRRScreenResources *resources; |
| 509 |
RROutput primary_output = None; |
| 510 |
RROutput first_output = None; |
| 511 |
int i; |
| 512 |
gboolean randr12_compat = FALSE; |
| 513 |
XRRMonitorInfo *rr_monitors; |
| 514 |
int num_rr_monitors; |
| 515 |
int old_primary; |
| 516 |
|
| 517 |
if (!x11_display->have_randr15) |
| 518 |
return FALSE; |
| 519 |
|
| 520 |
resources = XRRGetScreenResourcesCurrent (x11_screen->xdisplay, |
| 521 |
x11_screen->xroot_window); |
| 522 |
if (!resources) |
| 523 |
return FALSE; |
| 524 |
|
| 525 |
rr_monitors = XRRGetMonitors (x11_screen->xdisplay, |
| 526 |
x11_screen->xroot_window, |
| 527 |
True, |
| 528 |
&num_rr_monitors); |
| 529 |
if (!rr_monitors) |
| 530 |
return FALSE; |
| 531 |
|
| 532 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 533 |
{ |
| 534 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 535 |
monitor->add = FALSE; |
| 536 |
monitor->remove = TRUE; |
| 537 |
} |
| 538 |
|
| 539 |
for (i = 0; i < num_rr_monitors; i++) |
| 540 |
{ |
| 541 |
RROutput output = rr_monitors[i].outputs[0]; |
| 542 |
XRROutputInfo *output_info; |
| 543 |
GdkX11Monitor *monitor; |
| 544 |
GdkRectangle geometry; |
| 545 |
GdkRectangle newgeo; |
| 546 |
char *name; |
| 547 |
char *manufacturer = NULL; |
| 548 |
int refresh_rate = 0; |
| 549 |
|
| 550 |
gdk_x11_display_error_trap_push (display); |
| 551 |
output_info = XRRGetOutputInfo (x11_screen->xdisplay, resources, output); |
| 552 |
if (gdk_x11_display_error_trap_pop (display)) |
| 553 |
continue; |
| 554 |
|
| 555 |
if (output_info == NULL) |
| 556 |
continue; |
| 557 |
|
| 558 |
/* Non RandR1.2+ X driver have output name "default" */ |
| 559 |
randr12_compat |= !g_strcmp0 (output_info->name, "default"); |
| 560 |
|
| 561 |
if (output_info->connection == RR_Disconnected) |
| 562 |
{ |
| 563 |
XRRFreeOutputInfo (output_info); |
| 564 |
continue; |
| 565 |
} |
| 566 |
|
| 567 |
if (first_output == None) |
| 568 |
first_output = output; |
| 569 |
|
| 570 |
if (output_info->crtc) |
| 571 |
{ |
| 572 |
XRRCrtcInfo *crtc; |
| 573 |
int j; |
| 574 |
|
| 575 |
gdk_x11_display_error_trap_push (display); |
| 576 |
crtc = XRRGetCrtcInfo (x11_screen->xdisplay, resources, |
| 577 |
output_info->crtc); |
| 578 |
if (gdk_x11_display_error_trap_pop (display)) |
| 579 |
{ |
| 580 |
XRRFreeOutputInfo (output_info); |
| 581 |
continue; |
| 582 |
} |
| 583 |
|
| 584 |
for (j = 0; j < resources->nmode; j++) |
| 585 |
{ |
| 586 |
XRRModeInfo *xmode = &resources->modes[j]; |
| 587 |
if (xmode->id == crtc->mode) |
| 588 |
{ |
| 589 |
if (xmode->hTotal != 0 && xmode->vTotal != 0) |
| 590 |
refresh_rate = (1000ULL * xmode->dotClock) / (xmode->hTotal * xmode->vTotal); |
| 591 |
break; |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
XRRFreeCrtcInfo (crtc); |
| 596 |
} |
| 597 |
|
| 598 |
/* Fetch minimal manufacturer information (PNP ID) from EDID */ |
| 599 |
{ |
| 600 |
#define EDID_LENGTH 128 |
| 601 |
Atom actual_type, edid_atom; |
| 602 |
char tmp[3]; |
| 603 |
int actual_format; |
| 604 |
unsigned char *prop; |
| 605 |
unsigned long nbytes, bytes_left; |
| 606 |
Display *disp = GDK_DISPLAY_XDISPLAY (x11_display); |
| 607 |
|
| 608 |
edid_atom = XInternAtom (disp, RR_PROPERTY_RANDR_EDID, FALSE); |
| 609 |
|
| 610 |
gdk_x11_display_error_trap_push (display); |
| 611 |
XRRGetOutputProperty (disp, output, |
| 612 |
edid_atom, |
| 613 |
0, |
| 614 |
EDID_LENGTH, |
| 615 |
FALSE, |
| 616 |
FALSE, |
| 617 |
AnyPropertyType, |
| 618 |
&actual_type, |
| 619 |
&actual_format, |
| 620 |
&nbytes, |
| 621 |
&bytes_left, |
| 622 |
&prop); |
| 623 |
if (gdk_x11_display_error_trap_pop (display)) |
| 624 |
{ |
| 625 |
XRRFreeOutputInfo (output_info); |
| 626 |
continue; |
| 627 |
} |
| 628 |
|
| 629 |
// Check partial EDID header (whole header: 00 ff ff ff ff ff ff 00) |
| 630 |
if (nbytes >= EDID_LENGTH && prop[0] == 0x00 && prop[1] == 0xff) |
| 631 |
{ |
| 632 |
/* decode the Vendor ID from three 5 bit words packed into 2 bytes |
| 633 |
* /--08--\/--09--\ |
| 634 |
* 7654321076543210 |
| 635 |
* |\---/\---/\---/ |
| 636 |
* R C1 C2 C3 */ |
| 637 |
tmp[0] = 'A' + ((prop[8] & 0x7c) / 4) - 1; |
| 638 |
tmp[1] = 'A' + ((prop[8] & 0x3) * 8) + ((prop[9] & 0xe0) / 32) - 1; |
| 639 |
tmp[2] = 'A' + (prop[9] & 0x1f) - 1; |
| 640 |
|
| 641 |
manufacturer = g_strndup (tmp, sizeof (tmp)); |
| 642 |
} |
| 643 |
|
| 644 |
XFree(prop); |
| 645 |
#undef EDID_LENGTH |
| 646 |
} |
| 647 |
|
| 648 |
name = gdk_x11_get_xatom_name_for_display (display, rr_monitors[i].name); |
| 649 |
monitor = find_monitor_by_name (x11_display, name); |
| 650 |
if (monitor) |
| 651 |
monitor->remove = FALSE; |
| 652 |
else |
| 653 |
{ |
| 654 |
monitor = g_object_new (GDK_TYPE_X11_MONITOR, |
| 655 |
"display", display, |
| 656 |
NULL); |
| 657 |
monitor->output = output; |
| 658 |
monitor->name = g_strdup (name); |
| 659 |
monitor->add = TRUE; |
| 660 |
g_ptr_array_add (x11_display->monitors, monitor); |
| 661 |
} |
| 662 |
|
| 663 |
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); |
| 664 |
|
| 665 |
newgeo.x = rr_monitors[i].x / x11_screen->window_scale; |
| 666 |
newgeo.y = rr_monitors[i].y / x11_screen->window_scale; |
| 667 |
newgeo.width = rr_monitors[i].width / x11_screen->window_scale; |
| 668 |
newgeo.height = rr_monitors[i].height / x11_screen->window_scale; |
| 669 |
if (newgeo.x != geometry.x || |
| 670 |
newgeo.y != geometry.y || |
| 671 |
newgeo.width != geometry.width || |
| 672 |
newgeo.height != geometry.height || |
| 673 |
rr_monitors[i].mwidth != gdk_monitor_get_width_mm (GDK_MONITOR (monitor)) || |
| 674 |
rr_monitors[i].mheight != gdk_monitor_get_height_mm (GDK_MONITOR (monitor)) || |
| 675 |
g_strcmp0 (name, gdk_monitor_get_model (GDK_MONITOR (monitor)))) |
| 676 |
*changed = TRUE; |
| 677 |
|
| 678 |
gdk_monitor_set_position (GDK_MONITOR (monitor), newgeo.x, newgeo.y); |
| 679 |
gdk_monitor_set_size (GDK_MONITOR (monitor), newgeo.width, newgeo.height); |
| 680 |
g_object_notify (G_OBJECT (monitor), "workarea"); |
| 681 |
gdk_monitor_set_physical_size (GDK_MONITOR (monitor), |
| 682 |
rr_monitors[i].mwidth, |
| 683 |
rr_monitors[i].mheight); |
| 684 |
gdk_monitor_set_subpixel_layout (GDK_MONITOR (monitor), |
| 685 |
translate_subpixel_order (output_info->subpixel_order)); |
| 686 |
gdk_monitor_set_refresh_rate (GDK_MONITOR (monitor), refresh_rate); |
| 687 |
gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), x11_screen->window_scale); |
| 688 |
gdk_monitor_set_model (GDK_MONITOR (monitor), name); |
| 689 |
gdk_monitor_set_connector (GDK_MONITOR (monitor), name); |
| 690 |
gdk_monitor_set_manufacturer (GDK_MONITOR (monitor), manufacturer); |
| 691 |
g_free (manufacturer); |
| 692 |
|
| 693 |
if (rr_monitors[i].primary) |
| 694 |
primary_output = monitor->output; |
| 695 |
|
| 696 |
XRRFreeOutputInfo (output_info); |
| 697 |
} |
| 698 |
|
| 699 |
XRRFreeMonitors (rr_monitors); |
| 700 |
XRRFreeScreenResources (resources); |
| 701 |
|
| 702 |
/* non RandR 1.2+ X driver doesn't return any usable multihead data */ |
| 703 |
if (randr12_compat) |
| 704 |
{ |
| 705 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 706 |
{ |
| 707 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 708 |
if (monitor->remove) |
| 709 |
gdk_display_monitor_removed (display, GDK_MONITOR (monitor)); |
| 710 |
} |
| 711 |
g_ptr_array_remove_range (x11_display->monitors, 0, x11_display->monitors->len); |
| 712 |
return FALSE; |
| 713 |
} |
| 714 |
|
| 715 |
for (i = x11_display->monitors->len - 1; i >= 0; i--) |
| 716 |
{ |
| 717 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 718 |
if (monitor->add) |
| 719 |
{ |
| 720 |
gdk_display_monitor_added (display, GDK_MONITOR (monitor)); |
| 721 |
*changed = TRUE; |
| 722 |
} |
| 723 |
else if (monitor->remove) |
| 724 |
{ |
| 725 |
g_object_ref (monitor); |
| 726 |
g_ptr_array_remove (x11_display->monitors, monitor); |
| 727 |
gdk_display_monitor_removed (display, GDK_MONITOR (monitor)); |
| 728 |
g_object_unref (monitor); |
| 729 |
*changed = TRUE; |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
old_primary = x11_display->primary_monitor; |
| 734 |
x11_display->primary_monitor = 0; |
| 735 |
for (i = 0; i < x11_display->monitors->len; ++i) |
| 736 |
{ |
| 737 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 738 |
if (monitor->output == primary_output) |
| 739 |
{ |
| 740 |
x11_display->primary_monitor = i; |
| 741 |
break; |
| 742 |
} |
| 743 |
|
| 744 |
/* No RandR1.3+ available or no primary set, fall back to prefer LVDS as primary if present */ |
| 745 |
if (primary_output == None && |
| 746 |
g_ascii_strncasecmp (gdk_monitor_get_model (GDK_MONITOR (monitor)), "LVDS", 4) == 0) |
| 747 |
{ |
| 748 |
x11_display->primary_monitor = i; |
| 749 |
break; |
| 750 |
} |
| 751 |
|
| 752 |
/* No primary specified and no LVDS found */ |
| 753 |
if (monitor->output == first_output) |
| 754 |
x11_display->primary_monitor = i; |
| 755 |
} |
| 756 |
|
| 757 |
if (x11_display->primary_monitor != old_primary) |
| 758 |
*changed = TRUE; |
| 759 |
|
| 760 |
return x11_display->monitors->len > 0; |
| 761 |
#endif |
| 762 |
|
| 763 |
return FALSE; |
| 764 |
} |
| 765 |
|
| 766 |
static gboolean |
| 767 |
init_randr13 (GdkScreen *screen, gboolean *changed) |
| 768 |
{ |
| 769 |
#ifdef HAVE_RANDR |
| 770 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 771 |
GdkX11Display *x11_display = GDK_X11_DISPLAY (display); |
| 772 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 773 |
XRRScreenResources *resources; |
| 774 |
RROutput primary_output = None; |
| 775 |
RROutput first_output = None; |
| 776 |
int i; |
| 777 |
gboolean randr12_compat = FALSE; |
| 778 |
int old_primary; |
| 779 |
|
| 780 |
if (!x11_display->have_randr13) |
| 781 |
return FALSE; |
| 782 |
|
| 783 |
resources = XRRGetScreenResourcesCurrent (x11_screen->xdisplay, |
| 784 |
x11_screen->xroot_window); |
| 785 |
if (!resources) |
| 786 |
return FALSE; |
| 787 |
|
| 788 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 789 |
{ |
| 790 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 791 |
monitor->add = FALSE; |
| 792 |
monitor->remove = TRUE; |
| 793 |
} |
| 794 |
|
| 795 |
for (i = 0; i < resources->noutput; ++i) |
| 796 |
{ |
| 797 |
RROutput output = resources->outputs[i]; |
| 798 |
XRROutputInfo *output_info; |
| 799 |
|
| 800 |
gdk_x11_display_error_trap_push (display); |
| 801 |
output_info = XRRGetOutputInfo (x11_screen->xdisplay, resources, output); |
| 802 |
|
| 803 |
if (gdk_x11_display_error_trap_pop (display)) |
| 804 |
continue; |
| 805 |
|
| 806 |
/* Non RandR1.2+ X driver have output name "default" */ |
| 807 |
randr12_compat |= !g_strcmp0 (output_info->name, "default"); |
| 808 |
|
| 809 |
if (output_info->connection == RR_Disconnected) |
| 810 |
{ |
| 811 |
XRRFreeOutputInfo (output_info); |
| 812 |
continue; |
| 813 |
} |
| 814 |
|
| 815 |
if (output_info->crtc) |
| 816 |
{ |
| 817 |
GdkX11Monitor *monitor; |
| 818 |
XRRCrtcInfo *crtc; |
| 819 |
char *name; |
| 820 |
GdkRectangle geometry; |
| 821 |
GdkRectangle newgeo; |
| 822 |
int j; |
| 823 |
int refresh_rate = 0; |
| 824 |
|
| 825 |
gdk_x11_display_error_trap_push (display); |
| 826 |
crtc = XRRGetCrtcInfo (x11_screen->xdisplay, resources, output_info->crtc); |
| 827 |
|
| 828 |
if (gdk_x11_display_error_trap_pop (display)) |
| 829 |
{ |
| 830 |
XRRFreeOutputInfo (output_info); |
| 831 |
continue; |
| 832 |
} |
| 833 |
|
| 834 |
for (j = 0; j < resources->nmode; j++) |
| 835 |
{ |
| 836 |
XRRModeInfo *xmode = &resources->modes[j]; |
| 837 |
if (xmode->id == crtc->mode) |
| 838 |
{ |
| 839 |
if (xmode->hTotal != 0 && xmode->vTotal != 0) |
| 840 |
refresh_rate = (1000ULL * xmode->dotClock) / (xmode->hTotal * xmode->vTotal); |
| 841 |
break; |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
name = g_strndup (output_info->name, output_info->nameLen); |
| 846 |
monitor = find_monitor_by_name (x11_display, name); |
| 847 |
if (monitor) |
| 848 |
monitor->remove = FALSE; |
| 849 |
else |
| 850 |
{ |
| 851 |
monitor = g_object_new (gdk_x11_monitor_get_type (), |
| 852 |
"display", display, |
| 853 |
NULL); |
| 854 |
monitor->name = g_strdup (name); |
| 855 |
monitor->output = output; |
| 856 |
monitor->add = TRUE; |
| 857 |
g_ptr_array_add (x11_display->monitors, monitor); |
| 858 |
} |
| 859 |
|
| 860 |
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); |
| 861 |
|
| 862 |
newgeo.x = crtc->x / x11_screen->window_scale; |
| 863 |
newgeo.y = crtc->y / x11_screen->window_scale; |
| 864 |
newgeo.width = crtc->width / x11_screen->window_scale; |
| 865 |
newgeo.height = crtc->height / x11_screen->window_scale; |
| 866 |
if (newgeo.x != geometry.x || |
| 867 |
newgeo.y != geometry.y || |
| 868 |
newgeo.width != geometry.width || |
| 869 |
newgeo.height != geometry.height || |
| 870 |
output_info->mm_width != gdk_monitor_get_width_mm (GDK_MONITOR (monitor)) || |
| 871 |
output_info->mm_height != gdk_monitor_get_height_mm (GDK_MONITOR (monitor)) || |
| 872 |
g_strcmp0 (name, gdk_monitor_get_model (GDK_MONITOR (monitor))) != 0) |
| 873 |
*changed = TRUE; |
| 874 |
|
| 875 |
gdk_monitor_set_position (GDK_MONITOR (monitor), newgeo.x, newgeo.y); |
| 876 |
gdk_monitor_set_size (GDK_MONITOR (monitor), newgeo.width, newgeo.height); |
| 877 |
g_object_notify (G_OBJECT (monitor), "workarea"); |
| 878 |
gdk_monitor_set_physical_size (GDK_MONITOR (monitor), |
| 879 |
output_info->mm_width, |
| 880 |
output_info->mm_height); |
| 881 |
gdk_monitor_set_subpixel_layout (GDK_MONITOR (monitor), |
| 882 |
translate_subpixel_order (output_info->subpixel_order)); |
| 883 |
gdk_monitor_set_refresh_rate (GDK_MONITOR (monitor), refresh_rate); |
| 884 |
gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), x11_screen->window_scale); |
| 885 |
gdk_monitor_set_model (GDK_MONITOR (monitor), name); |
| 886 |
|
| 887 |
g_free (name); |
| 888 |
|
| 889 |
XRRFreeCrtcInfo (crtc); |
| 890 |
} |
| 891 |
|
| 892 |
XRRFreeOutputInfo (output_info); |
| 893 |
} |
| 894 |
|
| 895 |
if (resources->noutput > 0) |
| 896 |
first_output = resources->outputs[0]; |
| 897 |
|
| 898 |
XRRFreeScreenResources (resources); |
| 899 |
|
| 900 |
if (randr12_compat) |
| 901 |
{ |
| 902 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 903 |
{ |
| 904 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 905 |
if (monitor->remove) |
| 906 |
gdk_display_monitor_removed (display, GDK_MONITOR (monitor)); |
| 907 |
} |
| 908 |
g_ptr_array_remove_range (x11_display->monitors, 0, x11_display->monitors->len); |
| 909 |
return FALSE; |
| 910 |
} |
| 911 |
|
| 912 |
for (i = x11_display->monitors->len - 1; i >= 0; i--) |
| 913 |
{ |
| 914 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 915 |
if (monitor->add) |
| 916 |
{ |
| 917 |
gdk_display_monitor_added (display, GDK_MONITOR (monitor)); |
| 918 |
*changed = TRUE; |
| 919 |
} |
| 920 |
else if (monitor->remove) |
| 921 |
{ |
| 922 |
g_object_ref (monitor); |
| 923 |
g_ptr_array_remove (x11_display->monitors, monitor); |
| 924 |
gdk_display_monitor_removed (display, GDK_MONITOR (monitor)); |
| 925 |
g_object_unref (monitor); |
| 926 |
*changed = TRUE; |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
old_primary = x11_display->primary_monitor; |
| 931 |
x11_display->primary_monitor = 0; |
| 932 |
|
| 933 |
gdk_x11_display_error_trap_push (display); |
| 934 |
primary_output = XRRGetOutputPrimary (x11_screen->xdisplay, |
| 935 |
x11_screen->xroot_window); |
| 936 |
gdk_x11_display_error_trap_pop_ignored (display); |
| 937 |
|
| 938 |
for (i = 0; i < x11_display->monitors->len; ++i) |
| 939 |
{ |
| 940 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 941 |
if (monitor->output == primary_output) |
| 942 |
{ |
| 943 |
x11_display->primary_monitor = i; |
| 944 |
break; |
| 945 |
} |
| 946 |
|
| 947 |
/* No RandR1.3+ available or no primary set, fall back to prefer LVDS as primary if present */ |
| 948 |
if (primary_output == None && |
| 949 |
g_ascii_strncasecmp (gdk_monitor_get_model (GDK_MONITOR (monitor)), "LVDS", 4) == 0) |
| 950 |
{ |
| 951 |
x11_display->primary_monitor = i; |
| 952 |
break; |
| 953 |
} |
| 954 |
|
| 955 |
/* No primary specified and no LVDS found */ |
| 956 |
if (monitor->output == first_output) |
| 957 |
x11_display->primary_monitor = i; |
| 958 |
} |
| 959 |
|
| 960 |
if (x11_display->primary_monitor != old_primary) |
| 961 |
*changed = TRUE; |
| 962 |
|
| 963 |
return x11_display->monitors->len > 0; |
| 964 |
#endif |
| 965 |
|
| 966 |
return FALSE; |
| 967 |
} |
| 968 |
|
| 969 |
static void |
| 970 |
init_no_multihead (GdkScreen *screen, gboolean *changed) |
| 971 |
{ |
| 972 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 973 |
GdkX11Display *x11_display = GDK_X11_DISPLAY (display); |
| 974 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 975 |
GdkX11Monitor *monitor; |
| 976 |
GdkRectangle geometry; |
| 977 |
GdkRectangle newgeo; |
| 978 |
int i; |
| 979 |
|
| 980 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 981 |
{ |
| 982 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 983 |
monitor->add = FALSE; |
| 984 |
monitor->remove = TRUE; |
| 985 |
} |
| 986 |
|
| 987 |
if (x11_display->monitors->len > 0) |
| 988 |
{ |
| 989 |
monitor = x11_display->monitors->pdata[0]; |
| 990 |
monitor->remove = FALSE; |
| 991 |
} |
| 992 |
else |
| 993 |
{ |
| 994 |
monitor = g_object_new (gdk_x11_monitor_get_type (), |
| 995 |
"display", display, |
| 996 |
NULL); |
| 997 |
monitor->output = 0; |
| 998 |
monitor->add = TRUE; |
| 999 |
g_ptr_array_add (x11_display->monitors, monitor); |
| 1000 |
} |
| 1001 |
|
| 1002 |
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); |
| 1003 |
|
| 1004 |
newgeo.x = 0; |
| 1005 |
newgeo.y = 0; |
| 1006 |
newgeo.width = DisplayWidth (x11_display->xdisplay, x11_screen->screen_num) / |
| 1007 |
x11_screen->window_scale; |
| 1008 |
newgeo.height = DisplayHeight (x11_display->xdisplay, x11_screen->screen_num) / |
| 1009 |
x11_screen->window_scale; |
| 1010 |
|
| 1011 |
if (newgeo.x != geometry.x || |
| 1012 |
newgeo.y != geometry.y || |
| 1013 |
newgeo.width != geometry.width || |
| 1014 |
newgeo.height != geometry.height || |
| 1015 |
gdk_x11_screen_get_width_mm (screen) != gdk_monitor_get_width_mm (GDK_MONITOR (monitor)) || |
| 1016 |
gdk_x11_screen_get_height_mm (screen) != gdk_monitor_get_height_mm (GDK_MONITOR (monitor))) |
| 1017 |
*changed = TRUE; |
| 1018 |
|
| 1019 |
gdk_monitor_set_position (GDK_MONITOR (monitor), newgeo.x, newgeo.y); |
| 1020 |
gdk_monitor_set_size (GDK_MONITOR (monitor), newgeo.width, newgeo.height); |
| 1021 |
|
| 1022 |
g_object_notify (G_OBJECT (monitor), "workarea"); |
| 1023 |
gdk_monitor_set_physical_size (GDK_MONITOR (monitor), |
| 1024 |
gdk_x11_screen_get_width_mm (screen), |
| 1025 |
gdk_x11_screen_get_height_mm (screen)); |
| 1026 |
gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), x11_screen->window_scale); |
| 1027 |
|
| 1028 |
if (x11_display->primary_monitor != 0) |
| 1029 |
*changed = TRUE; |
| 1030 |
x11_display->primary_monitor = 0; |
| 1031 |
|
| 1032 |
for (i = x11_display->monitors->len - 1; i >= 0; i--) |
| 1033 |
{ |
| 1034 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 1035 |
if (monitor->add) |
| 1036 |
{ |
| 1037 |
gdk_display_monitor_added (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); |
| 1038 |
*changed = TRUE; |
| 1039 |
} |
| 1040 |
else if (monitor->remove) |
| 1041 |
{ |
| 1042 |
g_object_ref (monitor); |
| 1043 |
g_ptr_array_remove (x11_display->monitors, monitor); |
| 1044 |
gdk_display_monitor_removed (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); |
| 1045 |
g_object_unref (monitor); |
| 1046 |
*changed = TRUE; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
static gboolean |
| 1052 |
init_multihead (GdkScreen *screen) |
| 1053 |
{ |
| 1054 |
gboolean any_changed = FALSE; |
| 1055 |
|
| 1056 |
if (!init_randr15 (screen, &any_changed) && |
| 1057 |
!init_randr13 (screen, &any_changed)) |
| 1058 |
init_no_multihead (screen, &any_changed); |
| 1059 |
|
| 1060 |
return any_changed; |
| 1061 |
} |
| 1062 |
|
| 1063 |
static void |
| 1064 |
update_bounding_box (GdkScreen *screen) |
| 1065 |
{ |
| 1066 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1067 |
GdkX11Display *x11_display = GDK_X11_DISPLAY (x11_screen->display); |
| 1068 |
gint i, x1, y1, x2, y2; |
| 1069 |
|
| 1070 |
x1 = y1 = G_MAXINT; |
| 1071 |
x2 = y2 = G_MININT; |
| 1072 |
|
| 1073 |
for (i = 0; i < x11_display->monitors->len; i++) |
| 1074 |
{ |
| 1075 |
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; |
| 1076 |
GdkRectangle geometry; |
| 1077 |
|
| 1078 |
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); |
| 1079 |
x1 = MIN (x1, geometry.x); |
| 1080 |
y1 = MIN (y1, geometry.y); |
| 1081 |
x2 = MAX (x2, geometry.x + geometry.width); |
| 1082 |
y2 = MAX (y2, geometry.y + geometry.height); |
| 1083 |
} |
| 1084 |
|
| 1085 |
x11_screen->width = x2 - x1; |
| 1086 |
x11_screen->height = y2 - y1; |
| 1087 |
} |
| 1088 |
|
| 1089 |
GdkScreen * |
| 1090 |
_gdk_x11_screen_new (GdkDisplay *display, |
| 1091 |
gint screen_number) |
| 1092 |
{ |
| 1093 |
GdkScreen *screen; |
| 1094 |
GdkX11Screen *x11_screen; |
| 1095 |
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display); |
| 1096 |
const char *scale_str; |
| 1097 |
|
| 1098 |
screen = g_object_new (GDK_TYPE_X11_SCREEN, NULL); |
| 1099 |
|
| 1100 |
x11_screen = GDK_X11_SCREEN (screen); |
| 1101 |
x11_screen->display = display; |
| 1102 |
x11_screen->xdisplay = display_x11->xdisplay; |
| 1103 |
x11_screen->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number); |
| 1104 |
x11_screen->screen_num = screen_number; |
| 1105 |
x11_screen->xroot_window = RootWindow (display_x11->xdisplay,screen_number); |
| 1106 |
x11_screen->wmspec_check_window = None; |
| 1107 |
/* we want this to be always non-null */ |
| 1108 |
x11_screen->window_manager_name = g_strdup ("unknown"); |
| 1109 |
|
| 1110 |
scale_str = g_getenv ("GDK_SCALE"); |
| 1111 |
if (scale_str) |
| 1112 |
{ |
| 1113 |
x11_screen->fixed_window_scale = TRUE; |
| 1114 |
x11_screen->window_scale = atol (scale_str); |
| 1115 |
if (x11_screen->window_scale == 0) |
| 1116 |
x11_screen->window_scale = 1; |
| 1117 |
} |
| 1118 |
else |
| 1119 |
x11_screen->window_scale = 1; |
| 1120 |
|
| 1121 |
init_randr_support (screen); |
| 1122 |
init_multihead (screen); |
| 1123 |
|
| 1124 |
_gdk_x11_screen_init_visuals (screen); |
| 1125 |
_gdk_x11_screen_init_root_window (screen); |
| 1126 |
update_bounding_box (screen); |
| 1127 |
|
| 1128 |
return screen; |
| 1129 |
} |
| 1130 |
|
| 1131 |
void |
| 1132 |
_gdk_x11_screen_set_window_scale (GdkX11Screen *x11_screen, |
| 1133 |
gint scale) |
| 1134 |
{ |
| 1135 |
GList *toplevels, *l; |
| 1136 |
GdkWindow *root; |
| 1137 |
|
| 1138 |
if (x11_screen->window_scale == scale) |
| 1139 |
return; |
| 1140 |
|
| 1141 |
x11_screen->window_scale = scale; |
| 1142 |
|
| 1143 |
root = x11_screen->root_window; |
| 1144 |
GDK_WINDOW_IMPL_X11 (root->impl)->window_scale = scale; |
| 1145 |
|
| 1146 |
if (GDK_WINDOW_IMPL_X11 (root->impl)->cairo_surface) |
| 1147 |
cairo_surface_set_device_scale (GDK_WINDOW_IMPL_X11 (root->impl)->cairo_surface, |
| 1148 |
scale, scale); |
| 1149 |
|
| 1150 |
toplevels = gdk_screen_get_toplevel_windows (GDK_SCREEN (x11_screen)); |
| 1151 |
|
| 1152 |
for (l = toplevels; l != NULL; l = l->next) |
| 1153 |
{ |
| 1154 |
GdkWindow *window = l->data; |
| 1155 |
|
| 1156 |
_gdk_x11_window_set_window_scale (window, scale); |
| 1157 |
} |
| 1158 |
|
| 1159 |
process_monitors_change (GDK_SCREEN (x11_screen)); |
| 1160 |
} |
| 1161 |
|
| 1162 |
/* |
| 1163 |
* It is important that we first request the selection |
| 1164 |
* notification, and then setup the initial state of |
| 1165 |
* is_composited to avoid a race condition here. |
| 1166 |
*/ |
| 1167 |
void |
| 1168 |
_gdk_x11_screen_setup (GdkScreen *screen) |
| 1169 |
{ |
| 1170 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1171 |
|
| 1172 |
gdk_display_request_selection_notification (x11_screen->display, |
| 1173 |
gdk_x11_xatom_to_atom_for_display (x11_screen->display, get_cm_atom (x11_screen))); |
| 1174 |
x11_screen->is_composited = check_is_composited (x11_screen->display, x11_screen); |
| 1175 |
} |
| 1176 |
|
| 1177 |
static gboolean |
| 1178 |
gdk_x11_screen_is_composited (GdkScreen *screen) |
| 1179 |
{ |
| 1180 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1181 |
|
| 1182 |
return x11_screen->is_composited; |
| 1183 |
} |
| 1184 |
|
| 1185 |
static void |
| 1186 |
init_randr_support (GdkScreen *screen) |
| 1187 |
{ |
| 1188 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1189 |
|
| 1190 |
/* NB: This is also needed for XSettings, so don't remove. */ |
| 1191 |
XSelectInput (GDK_SCREEN_XDISPLAY (screen), |
| 1192 |
x11_screen->xroot_window, |
| 1193 |
StructureNotifyMask); |
| 1194 |
|
| 1195 |
#ifdef HAVE_RANDR |
| 1196 |
if (!GDK_X11_DISPLAY (gdk_screen_get_display (screen))->have_randr12) |
| 1197 |
return; |
| 1198 |
|
| 1199 |
XRRSelectInput (GDK_SCREEN_XDISPLAY (screen), |
| 1200 |
x11_screen->xroot_window, |
| 1201 |
RRScreenChangeNotifyMask |
| 1202 |
| RRCrtcChangeNotifyMask |
| 1203 |
| RROutputPropertyNotifyMask); |
| 1204 |
#endif |
| 1205 |
} |
| 1206 |
|
| 1207 |
static void |
| 1208 |
process_monitors_change (GdkScreen *screen) |
| 1209 |
{ |
| 1210 |
if (init_multihead (screen)) |
| 1211 |
{ |
| 1212 |
update_bounding_box (screen); |
| 1213 |
g_signal_emit_by_name (screen, "monitors-changed"); |
| 1214 |
} |
| 1215 |
} |
| 1216 |
|
| 1217 |
void |
| 1218 |
_gdk_x11_screen_size_changed (GdkScreen *screen, |
| 1219 |
XEvent *event) |
| 1220 |
{ |
| 1221 |
gint width, height; |
| 1222 |
#ifdef HAVE_RANDR |
| 1223 |
GdkX11Display *display_x11; |
| 1224 |
#endif |
| 1225 |
|
| 1226 |
width = gdk_x11_screen_get_width (screen); |
| 1227 |
height = gdk_x11_screen_get_height (screen); |
| 1228 |
|
| 1229 |
#ifdef HAVE_RANDR |
| 1230 |
display_x11 = GDK_X11_DISPLAY (gdk_screen_get_display (screen)); |
| 1231 |
|
| 1232 |
if (display_x11->have_randr13 && event->type == ConfigureNotify) |
| 1233 |
return; |
| 1234 |
|
| 1235 |
XRRUpdateConfiguration (event); |
| 1236 |
#else |
| 1237 |
if (event->type == ConfigureNotify) |
| 1238 |
{ |
| 1239 |
XConfigureEvent *rcevent = (XConfigureEvent *) event; |
| 1240 |
Screen *xscreen = gdk_x11_screen_get_xscreen (screen); |
| 1241 |
|
| 1242 |
xscreen->width = rcevent->width; |
| 1243 |
xscreen->height = rcevent->height; |
| 1244 |
} |
| 1245 |
else |
| 1246 |
return; |
| 1247 |
#endif |
| 1248 |
|
| 1249 |
process_monitors_change (screen); |
| 1250 |
|
| 1251 |
if (width != gdk_x11_screen_get_width (screen) || |
| 1252 |
height != gdk_x11_screen_get_height (screen)) |
| 1253 |
g_signal_emit_by_name (screen, "size-changed"); |
| 1254 |
} |
| 1255 |
|
| 1256 |
void |
| 1257 |
_gdk_x11_screen_get_edge_monitors (GdkScreen *screen, |
| 1258 |
gint *top, |
| 1259 |
gint *bottom, |
| 1260 |
gint *left, |
| 1261 |
gint *right) |
| 1262 |
{ |
| 1263 |
#ifdef HAVE_XFREE_XINERAMA |
| 1264 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1265 |
gint top_most_pos = x11_screen->height; |
| 1266 |
gint left_most_pos = x11_screen->width; |
| 1267 |
gint bottom_most_pos = 0; |
| 1268 |
gint right_most_pos = 0; |
| 1269 |
gint i; |
| 1270 |
XineramaScreenInfo *x_monitors; |
| 1271 |
int x_n_monitors; |
| 1272 |
#endif |
| 1273 |
|
| 1274 |
*top = *bottom = *left = *right = -1; |
| 1275 |
|
| 1276 |
#ifdef HAVE_XFREE_XINERAMA |
| 1277 |
if (!XineramaIsActive (x11_screen->xdisplay)) |
| 1278 |
return; |
| 1279 |
|
| 1280 |
x_monitors = XineramaQueryScreens (x11_screen->xdisplay, &x_n_monitors); |
| 1281 |
if (x_n_monitors <= 0 || x_monitors == NULL) |
| 1282 |
{ |
| 1283 |
if (x_monitors) |
| 1284 |
XFree (x_monitors); |
| 1285 |
|
| 1286 |
return; |
| 1287 |
} |
| 1288 |
|
| 1289 |
for (i = 0; i < x_n_monitors; i++) |
| 1290 |
{ |
| 1291 |
if (left && left_most_pos > x_monitors[i].x_org) |
| 1292 |
{ |
| 1293 |
left_most_pos = x_monitors[i].x_org; |
| 1294 |
*left = i; |
| 1295 |
} |
| 1296 |
if (right && right_most_pos < x_monitors[i].x_org + x_monitors[i].width) |
| 1297 |
{ |
| 1298 |
right_most_pos = x_monitors[i].x_org + x_monitors[i].width; |
| 1299 |
*right = i; |
| 1300 |
} |
| 1301 |
if (top && top_most_pos > x_monitors[i].y_org) |
| 1302 |
{ |
| 1303 |
top_most_pos = x_monitors[i].y_org; |
| 1304 |
*top = i; |
| 1305 |
} |
| 1306 |
if (bottom && bottom_most_pos < x_monitors[i].y_org + x_monitors[i].height) |
| 1307 |
{ |
| 1308 |
bottom_most_pos = x_monitors[i].y_org + x_monitors[i].height; |
| 1309 |
*bottom = i; |
| 1310 |
} |
| 1311 |
} |
| 1312 |
|
| 1313 |
XFree (x_monitors); |
| 1314 |
#endif |
| 1315 |
} |
| 1316 |
|
| 1317 |
void |
| 1318 |
_gdk_x11_screen_window_manager_changed (GdkScreen *screen) |
| 1319 |
{ |
| 1320 |
g_signal_emit (screen, signals[WINDOW_MANAGER_CHANGED], 0); |
| 1321 |
} |
| 1322 |
|
| 1323 |
void |
| 1324 |
_gdk_x11_screen_process_owner_change (GdkScreen *screen, |
| 1325 |
XEvent *event) |
| 1326 |
{ |
| 1327 |
#ifdef HAVE_XFIXES |
| 1328 |
XFixesSelectionNotifyEvent *selection_event = (XFixesSelectionNotifyEvent *)event; |
| 1329 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1330 |
|
| 1331 |
if (selection_event->selection == get_cm_atom (x11_screen)) |
| 1332 |
{ |
| 1333 |
gboolean composited = selection_event->owner != None; |
| 1334 |
|
| 1335 |
if (composited != x11_screen->is_composited) |
| 1336 |
{ |
| 1337 |
x11_screen->is_composited = composited; |
| 1338 |
|
| 1339 |
g_signal_emit_by_name (screen, "composited-changed"); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
#endif |
| 1343 |
} |
| 1344 |
|
| 1345 |
static gchar * |
| 1346 |
substitute_screen_number (const gchar *display_name, |
| 1347 |
gint screen_number) |
| 1348 |
{ |
| 1349 |
GString *str; |
| 1350 |
gchar *p; |
| 1351 |
|
| 1352 |
str = g_string_new (display_name); |
| 1353 |
|
| 1354 |
p = strrchr (str->str, '.'); |
| 1355 |
if (p && p > strchr (str->str, ':')) |
| 1356 |
g_string_truncate (str, p - str->str); |
| 1357 |
|
| 1358 |
g_string_append_printf (str, ".%d", screen_number); |
| 1359 |
|
| 1360 |
return g_string_free (str, FALSE); |
| 1361 |
} |
| 1362 |
|
| 1363 |
static gchar * |
| 1364 |
gdk_x11_screen_make_display_name (GdkScreen *screen) |
| 1365 |
{ |
| 1366 |
const gchar *old_display; |
| 1367 |
|
| 1368 |
old_display = gdk_display_get_name (gdk_screen_get_display (screen)); |
| 1369 |
|
| 1370 |
return substitute_screen_number (old_display, |
| 1371 |
gdk_x11_screen_get_number (screen)); |
| 1372 |
} |
| 1373 |
|
| 1374 |
static GdkWindow * |
| 1375 |
gdk_x11_screen_get_active_window (GdkScreen *screen) |
| 1376 |
{ |
| 1377 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1378 |
GdkWindow *ret = NULL; |
| 1379 |
Atom type_return; |
| 1380 |
gint format_return; |
| 1381 |
gulong nitems_return; |
| 1382 |
gulong bytes_after_return; |
| 1383 |
guchar *data = NULL; |
| 1384 |
|
| 1385 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, |
| 1386 |
gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) |
| 1387 |
return NULL; |
| 1388 |
|
| 1389 |
if (XGetWindowProperty (x11_screen->xdisplay, x11_screen->xroot_window, |
| 1390 |
gdk_x11_get_xatom_by_name_for_display (x11_screen->display, |
| 1391 |
"_NET_ACTIVE_WINDOW"), |
| 1392 |
0, 1, False, XA_WINDOW, &type_return, |
| 1393 |
&format_return, &nitems_return, |
| 1394 |
&bytes_after_return, &data) |
| 1395 |
== Success) |
| 1396 |
{ |
| 1397 |
if ((type_return == XA_WINDOW) && (format_return == 32) && (data)) |
| 1398 |
{ |
| 1399 |
Window window = *(Window *) data; |
| 1400 |
|
| 1401 |
if (window != None) |
| 1402 |
{ |
| 1403 |
ret = gdk_x11_window_foreign_new_for_display (x11_screen->display, |
| 1404 |
window); |
| 1405 |
} |
| 1406 |
} |
| 1407 |
} |
| 1408 |
|
| 1409 |
if (data) |
| 1410 |
XFree (data); |
| 1411 |
|
| 1412 |
return ret; |
| 1413 |
} |
| 1414 |
|
| 1415 |
static GList * |
| 1416 |
gdk_x11_screen_get_window_stack (GdkScreen *screen) |
| 1417 |
{ |
| 1418 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1419 |
GList *ret = NULL; |
| 1420 |
Atom type_return; |
| 1421 |
gint format_return; |
| 1422 |
gulong nitems_return; |
| 1423 |
gulong bytes_after_return; |
| 1424 |
guchar *data = NULL; |
| 1425 |
|
| 1426 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, |
| 1427 |
gdk_atom_intern_static_string ("_NET_CLIENT_LIST_STACKING"))) |
| 1428 |
return NULL; |
| 1429 |
|
| 1430 |
if (XGetWindowProperty (x11_screen->xdisplay, x11_screen->xroot_window, |
| 1431 |
gdk_x11_get_xatom_by_name_for_display (x11_screen->display, |
| 1432 |
"_NET_CLIENT_LIST_STACKING"), |
| 1433 |
0, G_MAXLONG, False, XA_WINDOW, &type_return, |
| 1434 |
&format_return, &nitems_return, |
| 1435 |
&bytes_after_return, &data) |
| 1436 |
== Success) |
| 1437 |
{ |
| 1438 |
if ((type_return == XA_WINDOW) && (format_return == 32) && |
| 1439 |
(data) && (nitems_return > 0)) |
| 1440 |
{ |
| 1441 |
gulong *stack = (gulong *) data; |
| 1442 |
GdkWindow *win; |
| 1443 |
int i; |
| 1444 |
|
| 1445 |
for (i = 0; i < nitems_return; i++) |
| 1446 |
{ |
| 1447 |
win = gdk_x11_window_foreign_new_for_display (x11_screen->display, |
| 1448 |
(Window)stack[i]); |
| 1449 |
|
| 1450 |
if (win != NULL) |
| 1451 |
ret = g_list_append (ret, win); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
if (data) |
| 1457 |
XFree (data); |
| 1458 |
|
| 1459 |
return ret; |
| 1460 |
} |
| 1461 |
|
| 1462 |
static gboolean |
| 1463 |
gdk_x11_screen_get_setting (GdkScreen *screen, |
| 1464 |
const gchar *name, |
| 1465 |
GValue *value) |
| 1466 |
{ |
| 1467 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1468 |
const GValue *setting; |
| 1469 |
|
| 1470 |
if (x11_screen->xsettings == NULL) |
| 1471 |
goto out; |
| 1472 |
setting = g_hash_table_lookup (x11_screen->xsettings, name); |
| 1473 |
if (setting == NULL) |
| 1474 |
goto out; |
| 1475 |
|
| 1476 |
if (!g_value_transform (setting, value)) |
| 1477 |
{ |
| 1478 |
g_warning ("Cannot transform xsetting %s of type %s to type %s\n", |
| 1479 |
name, |
| 1480 |
g_type_name (G_VALUE_TYPE (setting)), |
| 1481 |
g_type_name (G_VALUE_TYPE (value))); |
| 1482 |
goto out; |
| 1483 |
} |
| 1484 |
|
| 1485 |
return TRUE; |
| 1486 |
|
| 1487 |
out: |
| 1488 |
return _gdk_x11_get_xft_setting (screen, name, value); |
| 1489 |
} |
| 1490 |
|
| 1491 |
static void |
| 1492 |
cleanup_atoms(gpointer data) |
| 1493 |
{ |
| 1494 |
NetWmSupportedAtoms *supported_atoms = data; |
| 1495 |
if (supported_atoms->atoms) |
| 1496 |
XFree (supported_atoms->atoms); |
| 1497 |
g_free (supported_atoms); |
| 1498 |
} |
| 1499 |
|
| 1500 |
static Window |
| 1501 |
get_net_supporting_wm_check (GdkX11Screen *screen, |
| 1502 |
Window window) |
| 1503 |
{ |
| 1504 |
GdkDisplay *display; |
| 1505 |
Atom type; |
| 1506 |
gint format; |
| 1507 |
gulong n_items; |
| 1508 |
gulong bytes_after; |
| 1509 |
guchar *data; |
| 1510 |
Window value; |
| 1511 |
|
| 1512 |
display = screen->display; |
| 1513 |
type = None; |
| 1514 |
data = NULL; |
| 1515 |
value = None; |
| 1516 |
|
| 1517 |
gdk_x11_display_error_trap_push (display); |
| 1518 |
XGetWindowProperty (screen->xdisplay, window, |
| 1519 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"), |
| 1520 |
0, G_MAXLONG, False, XA_WINDOW, &type, &format, |
| 1521 |
&n_items, &bytes_after, &data); |
| 1522 |
gdk_x11_display_error_trap_pop_ignored (display); |
| 1523 |
|
| 1524 |
if (type == XA_WINDOW) |
| 1525 |
value = *(Window *)data; |
| 1526 |
|
| 1527 |
if (data) |
| 1528 |
XFree (data); |
| 1529 |
|
| 1530 |
return value; |
| 1531 |
} |
| 1532 |
|
| 1533 |
static void |
| 1534 |
fetch_net_wm_check_window (GdkScreen *screen) |
| 1535 |
{ |
| 1536 |
GdkX11Screen *x11_screen; |
| 1537 |
GdkDisplay *display; |
| 1538 |
Window window; |
| 1539 |
GTimeVal tv; |
| 1540 |
gint error; |
| 1541 |
|
| 1542 |
x11_screen = GDK_X11_SCREEN (screen); |
| 1543 |
display = x11_screen->display; |
| 1544 |
|
| 1545 |
g_return_if_fail (GDK_X11_DISPLAY (display)->trusted_client); |
| 1546 |
|
| 1547 |
if (x11_screen->wmspec_check_window != None) |
| 1548 |
return; /* already have it */ |
| 1549 |
|
| 1550 |
g_get_current_time (&tv); |
| 1551 |
|
| 1552 |
if (ABS (tv.tv_sec - x11_screen->last_wmspec_check_time) < 15) |
| 1553 |
return; /* we've checked recently */ |
| 1554 |
|
| 1555 |
window = get_net_supporting_wm_check (x11_screen, x11_screen->xroot_window); |
| 1556 |
if (window == None) |
| 1557 |
return; |
| 1558 |
|
| 1559 |
if (window != get_net_supporting_wm_check (x11_screen, window)) |
| 1560 |
return; |
| 1561 |
|
| 1562 |
gdk_x11_display_error_trap_push (display); |
| 1563 |
|
| 1564 |
/* Find out if this WM goes away, so we can reset everything. */ |
| 1565 |
XSelectInput (x11_screen->xdisplay, window, StructureNotifyMask); |
| 1566 |
|
| 1567 |
error = gdk_x11_display_error_trap_pop (display); |
| 1568 |
if (!error) |
| 1569 |
{ |
| 1570 |
/* We check the window property again because after XGetWindowProperty() |
| 1571 |
* and before XSelectInput() the window may have been recycled in such a |
| 1572 |
* way that XSelectInput() doesn't fail but the window is no longer what |
| 1573 |
* we want. |
| 1574 |
*/ |
| 1575 |
if (window != get_net_supporting_wm_check (x11_screen, window)) |
| 1576 |
return; |
| 1577 |
|
| 1578 |
x11_screen->wmspec_check_window = window; |
| 1579 |
x11_screen->last_wmspec_check_time = tv.tv_sec; |
| 1580 |
x11_screen->need_refetch_net_supported = TRUE; |
| 1581 |
x11_screen->need_refetch_wm_name = TRUE; |
| 1582 |
|
| 1583 |
/* Careful, reentrancy */ |
| 1584 |
_gdk_x11_screen_window_manager_changed (screen); |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
/** |
| 1589 |
* gdk_x11_screen_supports_net_wm_hint: |
| 1590 |
* @screen: (type GdkX11Screen): the relevant #GdkScreen. |
| 1591 |
* @property: a property atom. |
| 1592 |
* |
| 1593 |
* This function is specific to the X11 backend of GDK, and indicates |
| 1594 |
* whether the window manager supports a certain hint from the |
| 1595 |
* [Extended Window Manager Hints](https://specifications.freedesktop.org/wm/latest/) specification. |
| 1596 |
* |
| 1597 |
* When using this function, keep in mind that the window manager |
| 1598 |
* can change over time; so you shouldn’t use this function in |
| 1599 |
* a way that impacts persistent application state. A common bug |
| 1600 |
* is that your application can start up before the window manager |
| 1601 |
* does when the user logs in, and before the window manager starts |
| 1602 |
* gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property. |
| 1603 |
* You can monitor the window_manager_changed signal on #GdkScreen to detect |
| 1604 |
* a window manager change. |
| 1605 |
* |
| 1606 |
* Returns: %TRUE if the window manager supports @property |
| 1607 |
* |
| 1608 |
* Since: 2.2 |
| 1609 |
**/ |
| 1610 |
gboolean |
| 1611 |
gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen, |
| 1612 |
GdkAtom property) |
| 1613 |
{ |
| 1614 |
gulong i; |
| 1615 |
GdkX11Screen *x11_screen; |
| 1616 |
NetWmSupportedAtoms *supported_atoms; |
| 1617 |
GdkDisplay *display; |
| 1618 |
Atom atom; |
| 1619 |
|
| 1620 |
g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); |
| 1621 |
|
| 1622 |
x11_screen = GDK_X11_SCREEN (screen); |
| 1623 |
display = x11_screen->display; |
| 1624 |
|
| 1625 |
if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client)) |
| 1626 |
return FALSE; |
| 1627 |
|
| 1628 |
supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms"); |
| 1629 |
if (!supported_atoms) |
| 1630 |
{ |
| 1631 |
supported_atoms = g_new0 (NetWmSupportedAtoms, 1); |
| 1632 |
g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms); |
| 1633 |
} |
| 1634 |
|
| 1635 |
fetch_net_wm_check_window (screen); |
| 1636 |
|
| 1637 |
if (x11_screen->wmspec_check_window == None) |
| 1638 |
return FALSE; |
| 1639 |
|
| 1640 |
if (x11_screen->need_refetch_net_supported) |
| 1641 |
{ |
| 1642 |
/* WM has changed since we last got the supported list, |
| 1643 |
* refetch it. |
| 1644 |
*/ |
| 1645 |
Atom type; |
| 1646 |
gint format; |
| 1647 |
gulong bytes_after; |
| 1648 |
|
| 1649 |
x11_screen->need_refetch_net_supported = FALSE; |
| 1650 |
|
| 1651 |
if (supported_atoms->atoms) |
| 1652 |
XFree (supported_atoms->atoms); |
| 1653 |
|
| 1654 |
supported_atoms->atoms = NULL; |
| 1655 |
supported_atoms->n_atoms = 0; |
| 1656 |
|
| 1657 |
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), x11_screen->xroot_window, |
| 1658 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"), |
| 1659 |
0, G_MAXLONG, False, XA_ATOM, &type, &format, |
| 1660 |
&supported_atoms->n_atoms, &bytes_after, |
| 1661 |
(guchar **)&supported_atoms->atoms); |
| 1662 |
|
| 1663 |
if (type != XA_ATOM) |
| 1664 |
return FALSE; |
| 1665 |
} |
| 1666 |
|
| 1667 |
if (supported_atoms->atoms == NULL) |
| 1668 |
return FALSE; |
| 1669 |
|
| 1670 |
atom = gdk_x11_atom_to_xatom_for_display (display, property); |
| 1671 |
|
| 1672 |
for (i = 0; i < supported_atoms->n_atoms; i++) |
| 1673 |
{ |
| 1674 |
if (supported_atoms->atoms[i] == atom) |
| 1675 |
return TRUE; |
| 1676 |
} |
| 1677 |
|
| 1678 |
return FALSE; |
| 1679 |
} |
| 1680 |
|
| 1681 |
/** |
| 1682 |
* gdk_x11_screen_get_window_manager_name: |
| 1683 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 1684 |
* |
| 1685 |
* Returns the name of the window manager for @screen. |
| 1686 |
* |
| 1687 |
* Returns: the name of the window manager screen @screen, or |
| 1688 |
* "unknown" if the window manager is unknown. The string is owned by GDK |
| 1689 |
* and should not be freed. |
| 1690 |
* |
| 1691 |
* Since: 2.2 |
| 1692 |
**/ |
| 1693 |
const char* |
| 1694 |
gdk_x11_screen_get_window_manager_name (GdkScreen *screen) |
| 1695 |
{ |
| 1696 |
GdkX11Screen *x11_screen; |
| 1697 |
GdkDisplay *display; |
| 1698 |
|
| 1699 |
x11_screen = GDK_X11_SCREEN (screen); |
| 1700 |
display = x11_screen->display; |
| 1701 |
|
| 1702 |
if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client)) |
| 1703 |
return x11_screen->window_manager_name; |
| 1704 |
|
| 1705 |
fetch_net_wm_check_window (screen); |
| 1706 |
|
| 1707 |
if (x11_screen->need_refetch_wm_name) |
| 1708 |
{ |
| 1709 |
/* Get the name of the window manager */ |
| 1710 |
x11_screen->need_refetch_wm_name = FALSE; |
| 1711 |
|
| 1712 |
g_free (x11_screen->window_manager_name); |
| 1713 |
x11_screen->window_manager_name = g_strdup ("unknown"); |
| 1714 |
|
| 1715 |
if (x11_screen->wmspec_check_window != None) |
| 1716 |
{ |
| 1717 |
Atom type; |
| 1718 |
gint format; |
| 1719 |
gulong n_items; |
| 1720 |
gulong bytes_after; |
| 1721 |
gchar *name; |
| 1722 |
|
| 1723 |
name = NULL; |
| 1724 |
|
| 1725 |
gdk_x11_display_error_trap_push (display); |
| 1726 |
|
| 1727 |
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), |
| 1728 |
x11_screen->wmspec_check_window, |
| 1729 |
gdk_x11_get_xatom_by_name_for_display (display, |
| 1730 |
"_NET_WM_NAME"), |
| 1731 |
0, G_MAXLONG, False, |
| 1732 |
gdk_x11_get_xatom_by_name_for_display (display, |
| 1733 |
"UTF8_STRING"), |
| 1734 |
&type, &format, |
| 1735 |
&n_items, &bytes_after, |
| 1736 |
(guchar **)&name); |
| 1737 |
|
| 1738 |
gdk_x11_display_error_trap_pop_ignored (display); |
| 1739 |
|
| 1740 |
if (name != NULL) |
| 1741 |
{ |
| 1742 |
g_free (x11_screen->window_manager_name); |
| 1743 |
x11_screen->window_manager_name = g_strdup (name); |
| 1744 |
XFree (name); |
| 1745 |
} |
| 1746 |
} |
| 1747 |
} |
| 1748 |
|
| 1749 |
return GDK_X11_SCREEN (screen)->window_manager_name; |
| 1750 |
} |
| 1751 |
|
| 1752 |
static void |
| 1753 |
gdk_x11_screen_class_init (GdkX11ScreenClass *klass) |
| 1754 |
{ |
| 1755 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1756 |
GdkScreenClass *screen_class = GDK_SCREEN_CLASS (klass); |
| 1757 |
|
| 1758 |
object_class->dispose = gdk_x11_screen_dispose; |
| 1759 |
object_class->finalize = gdk_x11_screen_finalize; |
| 1760 |
|
| 1761 |
screen_class->get_display = gdk_x11_screen_get_display; |
| 1762 |
screen_class->get_width = gdk_x11_screen_get_width; |
| 1763 |
screen_class->get_height = gdk_x11_screen_get_height; |
| 1764 |
screen_class->get_width_mm = gdk_x11_screen_get_width_mm; |
| 1765 |
screen_class->get_height_mm = gdk_x11_screen_get_height_mm; |
| 1766 |
screen_class->get_number = gdk_x11_screen_get_number; |
| 1767 |
screen_class->get_root_window = gdk_x11_screen_get_root_window; |
| 1768 |
screen_class->get_system_visual = _gdk_x11_screen_get_system_visual; |
| 1769 |
screen_class->get_rgba_visual = gdk_x11_screen_get_rgba_visual; |
| 1770 |
screen_class->is_composited = gdk_x11_screen_is_composited; |
| 1771 |
screen_class->make_display_name = gdk_x11_screen_make_display_name; |
| 1772 |
screen_class->get_active_window = gdk_x11_screen_get_active_window; |
| 1773 |
screen_class->get_window_stack = gdk_x11_screen_get_window_stack; |
| 1774 |
screen_class->get_setting = gdk_x11_screen_get_setting; |
| 1775 |
screen_class->visual_get_best_depth = _gdk_x11_screen_visual_get_best_depth; |
| 1776 |
screen_class->visual_get_best_type = _gdk_x11_screen_visual_get_best_type; |
| 1777 |
screen_class->visual_get_best = _gdk_x11_screen_visual_get_best; |
| 1778 |
screen_class->visual_get_best_with_depth = _gdk_x11_screen_visual_get_best_with_depth; |
| 1779 |
screen_class->visual_get_best_with_type = _gdk_x11_screen_visual_get_best_with_type; |
| 1780 |
screen_class->visual_get_best_with_both = _gdk_x11_screen_visual_get_best_with_both; |
| 1781 |
screen_class->query_depths = _gdk_x11_screen_query_depths; |
| 1782 |
screen_class->query_visual_types = _gdk_x11_screen_query_visual_types; |
| 1783 |
screen_class->list_visuals = _gdk_x11_screen_list_visuals; |
| 1784 |
|
| 1785 |
signals[WINDOW_MANAGER_CHANGED] = |
| 1786 |
g_signal_new (g_intern_static_string ("window-manager-changed"), |
| 1787 |
G_OBJECT_CLASS_TYPE (object_class), |
| 1788 |
G_SIGNAL_RUN_LAST, |
| 1789 |
G_STRUCT_OFFSET (GdkX11ScreenClass, window_manager_changed), |
| 1790 |
NULL, NULL, |
| 1791 |
NULL, |
| 1792 |
G_TYPE_NONE, |
| 1793 |
0); |
| 1794 |
} |
| 1795 |
|
| 1796 |
static guint32 |
| 1797 |
get_netwm_cardinal_property (GdkScreen *screen, |
| 1798 |
const gchar *name) |
| 1799 |
{ |
| 1800 |
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); |
| 1801 |
GdkAtom atom; |
| 1802 |
guint32 prop = 0; |
| 1803 |
Atom type; |
| 1804 |
gint format; |
| 1805 |
gulong nitems; |
| 1806 |
gulong bytes_after; |
| 1807 |
guchar *data; |
| 1808 |
|
| 1809 |
atom = gdk_atom_intern_static_string (name); |
| 1810 |
|
| 1811 |
if (!gdk_x11_screen_supports_net_wm_hint (screen, atom)) |
| 1812 |
return 0; |
| 1813 |
|
| 1814 |
XGetWindowProperty (x11_screen->xdisplay, |
| 1815 |
x11_screen->xroot_window, |
| 1816 |
gdk_x11_get_xatom_by_name_for_display (GDK_SCREEN_DISPLAY (screen), name), |
| 1817 |
0, G_MAXLONG, |
| 1818 |
False, XA_CARDINAL, &type, &format, &nitems, |
| 1819 |
&bytes_after, &data); |
| 1820 |
if (type == XA_CARDINAL) |
| 1821 |
{ |
| 1822 |
prop = *(gulong *)data; |
| 1823 |
XFree (data); |
| 1824 |
} |
| 1825 |
|
| 1826 |
return prop; |
| 1827 |
} |
| 1828 |
|
| 1829 |
/** |
| 1830 |
* gdk_x11_screen_get_number_of_desktops: |
| 1831 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 1832 |
* |
| 1833 |
* Returns the number of workspaces for @screen when running under a |
| 1834 |
* window manager that supports multiple workspaces, as described |
| 1835 |
* in the |
| 1836 |
* [Extended Window Manager Hints](https://specifications.freedesktop.org/wm/latest/) specification. |
| 1837 |
* |
| 1838 |
* Returns: the number of workspaces, or 0 if workspaces are not supported |
| 1839 |
* |
| 1840 |
* Since: 3.10 |
| 1841 |
*/ |
| 1842 |
guint32 |
| 1843 |
gdk_x11_screen_get_number_of_desktops (GdkScreen *screen) |
| 1844 |
{ |
| 1845 |
return get_netwm_cardinal_property (screen, "_NET_NUMBER_OF_DESKTOPS"); |
| 1846 |
} |
| 1847 |
|
| 1848 |
/** |
| 1849 |
* gdk_x11_screen_get_current_desktop: |
| 1850 |
* @screen: (type GdkX11Screen): a #GdkScreen |
| 1851 |
* |
| 1852 |
* Returns the current workspace for @screen when running under a |
| 1853 |
* window manager that supports multiple workspaces, as described |
| 1854 |
* in the |
| 1855 |
* [Extended Window Manager Hints](https://specifications.freedesktop.org/wm/latest/) specification. |
| 1856 |
* |
| 1857 |
* Returns: the current workspace, or 0 if workspaces are not supported |
| 1858 |
* |
| 1859 |
* Since: 3.10 |
| 1860 |
*/ |
| 1861 |
guint32 |
| 1862 |
gdk_x11_screen_get_current_desktop (GdkScreen *screen) |
| 1863 |
{ |
| 1864 |
return get_netwm_cardinal_property (screen, "_NET_CURRENT_DESKTOP"); |
| 1865 |
} |