1455
1452
GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)),
1456
1453
width, height);
1458
/* Use this pixmap for the background */
1459
XSetWindowBackgroundPixmap (GDK_SCREEN_XDISPLAY (screen),
1460
RootWindow (GDK_SCREEN_XDISPLAY (screen), number),
1461
cairo_xlib_surface_get_drawable (surface));
1464
1455
return surface;
1468
set_background (GdkPixbuf *new_bg, gboolean is_locked)
1458
/* Sets the "ESETROOT_PMAP_ID" property to later be used to free the pixmap,
1461
set_root_pixmap_id (GdkScreen *screen,
1465
Window xroot = RootWindow (display, gdk_screen_get_number (screen));
1466
char *atom_names[] = {"_XROOTPMAP_ID", "ESETROOT_PMAP_ID"};
1467
Atom atoms[G_N_ELEMENTS(atom_names)] = {0};
1471
unsigned long nitems, after;
1472
unsigned char *data_root, *data_esetroot;
1474
/* Get atoms for both properties in an array, only if they exist.
1475
* This method is to avoid multiple round-trips to Xserver
1477
if (XInternAtoms (display, atom_names, G_N_ELEMENTS(atom_names), True, atoms) &&
1478
atoms[0] != None && atoms[1] != None)
1481
XGetWindowProperty (display, xroot, atoms[0], 0L, 1L, False, AnyPropertyType,
1482
&type, &format, &nitems, &after, &data_root);
1483
if (data_root && type == XA_PIXMAP && format == 32 && nitems == 1)
1485
XGetWindowProperty (display, xroot, atoms[1], 0L, 1L, False, AnyPropertyType,
1486
&type, &format, &nitems, &after, &data_esetroot);
1487
if (data_esetroot && type == XA_PIXMAP && format == 32 && nitems == 1)
1489
Pixmap xrootpmap = *((Pixmap *) data_root);
1490
Pixmap esetrootpmap = *((Pixmap *) data_esetroot);
1492
XFree (data_esetroot);
1494
gdk_error_trap_push ();
1495
if (xrootpmap && xrootpmap == esetrootpmap) {
1496
XKillClient (display, xrootpmap);
1498
if (esetrootpmap && esetrootpmap != xrootpmap) {
1499
XKillClient (display, esetrootpmap);
1502
XSync (display, False);
1504
gdk_error_trap_pop_ignored ();
1509
/* Get atoms for both properties in an array, create them if needed.
1510
* This method is to avoid multiple round-trips to Xserver
1512
if (!XInternAtoms (display, atom_names, G_N_ELEMENTS(atom_names), False, atoms) ||
1513
atoms[0] == None || atoms[1] == None) {
1514
g_warning("Could not create atoms needed to set root pixmap id/properties.\n");
1518
/* Set new _XROOTMAP_ID and ESETROOT_PMAP_ID properties */
1519
XChangeProperty (display, xroot, atoms[0], XA_PIXMAP, 32,
1520
PropModeReplace, (unsigned char *) &xpixmap, 1);
1522
XChangeProperty (display, xroot, atoms[1], XA_PIXMAP, 32,
1523
PropModeReplace, (unsigned char *) &xpixmap, 1);
1527
* set_surface_as_root:
1528
* @screen: the #GdkScreen to change root background on
1529
* @surface: the #cairo_surface_t to set root background from.
1530
* Must be an xlib surface backing a pixmap.
1532
* Set the root pixmap, and properties pointing to it. We
1533
* do this atomically with a server grab to make sure that
1534
* we won't leak the pixmap if somebody else it setting
1535
* it at the same time. (This assumes that they follow the
1536
* same conventions we do). @surface should come from a call
1537
* to create_root_surface().
1540
set_surface_as_root (GdkScreen *screen, cairo_surface_t *surface)
1542
g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB);
1544
/* Desktop background pixmap should be created from dummy X client since most
1545
* applications will try to kill it with XKillClient later when changing pixmap
1547
Display *display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
1548
Pixmap pixmap_id = cairo_xlib_surface_get_drawable (surface);
1549
Window xroot = RootWindow (display, gdk_screen_get_number (screen));
1551
XGrabServer (display);
1553
XSetWindowBackgroundPixmap (display, xroot, pixmap_id);
1554
set_root_pixmap_id (screen, display, pixmap_id);
1555
XClearWindow (display, xroot);
1558
XUngrabServer (display);
1562
set_background (GdkPixbuf *new_bg)
1470
1564
GdkRectangle monitor_geometry;
1471
1565
GdkPixbuf *bg = NULL;
1498
1592
p_width = gdk_pixbuf_get_width(bg);
1499
1593
p_height = gdk_pixbuf_get_height(bg);
1501
1595
scale = (double)monitor_geometry.width/p_width;
1502
1596
height = p_height * scale;
1503
1597
width = monitor_geometry.width;
1505
1599
if (height < monitor_geometry.height)
1507
1601
scale = (double)monitor_geometry.height/p_height;
1508
1602
height = monitor_geometry.height;
1509
1603
width = p_width * scale;
1513
1606
GdkPixbuf *p = gdk_pixbuf_scale_simple (bg, width,
1514
1607
height, GDK_INTERP_BILINEAR);
1515
1608
if (width > monitor_geometry.width)
1517
p = gdk_pixbuf_new_subpixbuf(p, (width-monitor_geometry.width)/2, 0, monitor_geometry.width, monitor_geometry.height);
1519
if (!gdk_pixbuf_get_has_alpha (p))
1520
p = gdk_pixbuf_add_alpha (p, FALSE, 255, 255, 255);
1610
GdkPixbuf *tmp = gdk_pixbuf_new_subpixbuf(p, (width-monitor_geometry.width)/2, 0, monitor_geometry.width, monitor_geometry.height);
1614
if (!gdk_pixbuf_get_has_alpha (p))
1616
GdkPixbuf *tmp = gdk_pixbuf_add_alpha (p, FALSE, 255, 255, 255);
1521
1620
gdk_cairo_set_source_pixbuf (c, p, monitor_geometry.x, monitor_geometry.y);
1522
1621
g_object_unref (p);