[gnome-flashback] common: move gf_background_surface_get_from_root to gf-bg
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] common: move gf_background_surface_get_from_root to gf-bg
- Date: Sat, 20 Mar 2021 21:41:47 +0000 (UTC)
commit 59c6c15d0c24bdb82dd1e6b9ff62410adb7d9734
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sat Mar 20 21:43:27 2021 +0200
common: move gf_background_surface_get_from_root to gf-bg
And rename to gf_bg_get_surface_from_root.
gnome-flashback/libcommon/gf-background-utils.c | 148 -----------------------
gnome-flashback/libcommon/gf-bg.c | 149 ++++++++++++++++++++++++
gnome-flashback/libcommon/gf-bg.h | 5 +
gnome-flashback/libdesktop/gf-background.c | 8 +-
gnome-flashback/libdesktop/gf-desktop-window.c | 9 +-
5 files changed, 160 insertions(+), 159 deletions(-)
---
diff --git a/gnome-flashback/libcommon/gf-background-utils.c b/gnome-flashback/libcommon/gf-background-utils.c
index 4c093ee..7c572a6 100644
--- a/gnome-flashback/libcommon/gf-background-utils.c
+++ b/gnome-flashback/libcommon/gf-background-utils.c
@@ -24,83 +24,6 @@
static const cairo_user_data_key_t average_color_key;
-static gboolean
-is_valid_pixmap (GdkDisplay *display,
- Pixmap pixmap)
-{
- Display *xdisplay;
- Window root_return;
- int x_return;
- int y_return;
- unsigned int width_return;
- unsigned int height_return;
- unsigned int border_width_return;
- unsigned int depth_return;
- Status status;
-
- xdisplay = gdk_x11_display_get_xdisplay (display);
-
- gdk_x11_display_error_trap_push (display);
-
- status = XGetGeometry (xdisplay, pixmap, &root_return,
- &x_return, &y_return, &width_return, &height_return,
- &border_width_return, &depth_return);
-
- if (gdk_x11_display_error_trap_pop (display) != 0 || status == 0)
- return FALSE;
-
- return TRUE;
-}
-
-static Pixmap
-get_root_pixmap (GdkDisplay *display)
-{
- Display *xdisplay;
- Atom xrootpmap_id_atom;
- int result;
- Atom actual_type;
- int actual_format;
- unsigned long n_items;
- unsigned long bytes_after;
- unsigned char *prop;
- Pixmap pixmap;
-
- xdisplay = gdk_x11_display_get_xdisplay (display);
- xrootpmap_id_atom = XInternAtom (xdisplay, "_XROOTPMAP_ID", False);
- prop = NULL;
-
- result = XGetWindowProperty (xdisplay,
- XDefaultRootWindow (xdisplay),
- xrootpmap_id_atom,
- 0l,
- 1l,
- False,
- XA_PIXMAP,
- &actual_type,
- &actual_format,
- &n_items,
- &bytes_after,
- &prop);
-
- if (result != Success ||
- actual_type != XA_PIXMAP ||
- actual_format != 32 ||
- n_items != 1)
- {
- XFree (prop);
-
- return None;
- }
-
- pixmap = *(Pixmap *) prop;
- XFree (prop);
-
- if (!is_valid_pixmap (display, pixmap))
- return None;
-
- return pixmap;
-}
-
static Pixmap
get_persistent_pixmap (cairo_surface_t *surface)
{
@@ -263,77 +186,6 @@ set_average_color (GdkDisplay *display,
}
}
-cairo_surface_t *
-gf_background_surface_get_from_root (GdkDisplay *display,
- int width,
- int height)
-{
- Display *xdisplay;
- Pixmap root_pixmap;
- GdkScreen *screen;
- GdkWindow *root;
- int scale;
- cairo_surface_t *pixmap_surface;
- cairo_surface_t *surface;
-
- xdisplay = gdk_x11_display_get_xdisplay (display);
-
- root_pixmap = get_root_pixmap (display);
-
- screen = gdk_display_get_default_screen (display);
- root = gdk_screen_get_root_window (screen);
- scale = gdk_window_get_scale_factor (root);
-
- pixmap_surface = NULL;
- surface = NULL;
-
- if (root_pixmap != None)
- {
- Visual *xvisual;
-
- xvisual = DefaultVisual (xdisplay, DefaultScreen (xdisplay));
-
- pixmap_surface = cairo_xlib_surface_create (xdisplay,
- root_pixmap,
- xvisual,
- width * scale,
- height * scale);
- }
-
- if (pixmap_surface != NULL)
- {
- cairo_t *cr;
-
- surface = cairo_surface_create_similar (pixmap_surface,
- CAIRO_CONTENT_COLOR,
- width * scale,
- height * scale);
-
- cr = cairo_create (surface);
- cairo_set_source_surface (cr, pixmap_surface, 0, 0);
- cairo_surface_destroy (pixmap_surface);
-
- cairo_paint (cr);
-
- if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
- g_clear_pointer (&surface, cairo_surface_destroy);
-
- cairo_destroy (cr);
- }
-
- if (surface != NULL)
- {
- cairo_surface_set_device_scale (surface, scale, scale);
-
- return surface;
- }
-
- return gdk_window_create_similar_surface (root,
- CAIRO_CONTENT_COLOR,
- width,
- height);
-}
-
void
gf_background_surface_set_as_root (GdkDisplay *display,
cairo_surface_t *surface)
diff --git a/gnome-flashback/libcommon/gf-bg.c b/gnome-flashback/libcommon/gf-bg.c
index e6fc5b9..fb9356d 100644
--- a/gnome-flashback/libcommon/gf-bg.c
+++ b/gnome-flashback/libcommon/gf-bg.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2000 Eazel, Inc.
* Copyright (C) 2007-2008 Red Hat, Inc.
+ * Copyright (C) 2019-2021 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -1586,6 +1587,83 @@ pixbuf_tile (GdkPixbuf *src, GdkPixbuf *dest)
}
}
+static gboolean
+is_valid_pixmap (GdkDisplay *display,
+ Pixmap pixmap)
+{
+ Display *xdisplay;
+ Window root_return;
+ int x_return;
+ int y_return;
+ unsigned int width_return;
+ unsigned int height_return;
+ unsigned int border_width_return;
+ unsigned int depth_return;
+ Status status;
+
+ xdisplay = gdk_x11_display_get_xdisplay (display);
+
+ gdk_x11_display_error_trap_push (display);
+
+ status = XGetGeometry (xdisplay, pixmap, &root_return,
+ &x_return, &y_return, &width_return, &height_return,
+ &border_width_return, &depth_return);
+
+ if (gdk_x11_display_error_trap_pop (display) != 0 || status == 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static Pixmap
+get_root_pixmap (GdkDisplay *display)
+{
+ Display *xdisplay;
+ Atom xrootpmap_id_atom;
+ int result;
+ Atom actual_type;
+ int actual_format;
+ unsigned long n_items;
+ unsigned long bytes_after;
+ unsigned char *prop;
+ Pixmap pixmap;
+
+ xdisplay = gdk_x11_display_get_xdisplay (display);
+ xrootpmap_id_atom = XInternAtom (xdisplay, "_XROOTPMAP_ID", False);
+ prop = NULL;
+
+ result = XGetWindowProperty (xdisplay,
+ XDefaultRootWindow (xdisplay),
+ xrootpmap_id_atom,
+ 0l,
+ 1l,
+ False,
+ XA_PIXMAP,
+ &actual_type,
+ &actual_format,
+ &n_items,
+ &bytes_after,
+ &prop);
+
+ if (result != Success ||
+ actual_type != XA_PIXMAP ||
+ actual_format != 32 ||
+ n_items != 1)
+ {
+ XFree (prop);
+
+ return None;
+ }
+
+ pixmap = *(Pixmap *) prop;
+ XFree (prop);
+
+ if (!is_valid_pixmap (display, pixmap))
+ return None;
+
+ return pixmap;
+}
+
static void
gf_bg_dispose (GObject *object)
{
@@ -1947,6 +2025,77 @@ gf_bg_set_surface_as_root (GdkScreen *screen,
gdk_x11_display_ungrab (gdk_screen_get_display (screen));
}
+cairo_surface_t *
+gf_bg_get_surface_from_root (GdkDisplay *display,
+ int width,
+ int height)
+{
+ Display *xdisplay;
+ Pixmap root_pixmap;
+ GdkScreen *screen;
+ GdkWindow *root;
+ int scale;
+ cairo_surface_t *pixmap_surface;
+ cairo_surface_t *surface;
+
+ xdisplay = gdk_x11_display_get_xdisplay (display);
+
+ root_pixmap = get_root_pixmap (display);
+
+ screen = gdk_display_get_default_screen (display);
+ root = gdk_screen_get_root_window (screen);
+ scale = gdk_window_get_scale_factor (root);
+
+ pixmap_surface = NULL;
+ surface = NULL;
+
+ if (root_pixmap != None)
+ {
+ Visual *xvisual;
+
+ xvisual = DefaultVisual (xdisplay, DefaultScreen (xdisplay));
+
+ pixmap_surface = cairo_xlib_surface_create (xdisplay,
+ root_pixmap,
+ xvisual,
+ width * scale,
+ height * scale);
+ }
+
+ if (pixmap_surface != NULL)
+ {
+ cairo_t *cr;
+
+ surface = cairo_surface_create_similar (pixmap_surface,
+ CAIRO_CONTENT_COLOR,
+ width * scale,
+ height * scale);
+
+ cr = cairo_create (surface);
+ cairo_set_source_surface (cr, pixmap_surface, 0, 0);
+ cairo_surface_destroy (pixmap_surface);
+
+ cairo_paint (cr);
+
+ if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
+ g_clear_pointer (&surface, cairo_surface_destroy);
+
+ cairo_destroy (cr);
+ }
+
+ if (surface != NULL)
+ {
+ cairo_surface_set_device_scale (surface, scale, scale);
+
+ return surface;
+ }
+
+ return gdk_window_create_similar_surface (root,
+ CAIRO_CONTENT_COLOR,
+ width,
+ height);
+}
+
GdkRGBA *
gf_bg_get_average_color_from_surface (cairo_surface_t *surface)
{
diff --git a/gnome-flashback/libcommon/gf-bg.h b/gnome-flashback/libcommon/gf-bg.h
index 1426461..577d982 100644
--- a/gnome-flashback/libcommon/gf-bg.h
+++ b/gnome-flashback/libcommon/gf-bg.h
@@ -1,5 +1,6 @@
/*
* Copyright 2007, Red Hat, Inc.
+ * Copyright 2019-2021 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -58,6 +59,10 @@ cairo_surface_t *gf_bg_create_surface (GfBG
void gf_bg_set_surface_as_root (GdkScreen *screen,
cairo_surface_t *surface);
+cairo_surface_t *gf_bg_get_surface_from_root (GdkDisplay *display,
+ int width,
+ int height);
+
GdkRGBA *gf_bg_get_average_color_from_surface (cairo_surface_t *surface);
G_END_DECLS
diff --git a/gnome-flashback/libdesktop/gf-background.c b/gnome-flashback/libdesktop/gf-background.c
index a0a8815..ea14582 100644
--- a/gnome-flashback/libdesktop/gf-background.c
+++ b/gnome-flashback/libdesktop/gf-background.c
@@ -18,10 +18,8 @@
#include "config.h"
#include "gf-background.h"
-#include "libcommon/gf-background-utils.h"
-#include "libcommon/gf-bg.h"
-
#include "gf-desktop-window.h"
+#include "libcommon/gf-bg.h"
typedef struct
{
@@ -166,9 +164,7 @@ change (GfBackground *self,
if (self->surface != NULL)
data->start = cairo_surface_reference (self->surface);
else
- data->start = gf_background_surface_get_from_root (display,
- width,
- height);
+ data->start = gf_bg_get_surface_from_root (display, width, height);
data->end = gf_bg_create_surface (self->bg, root, width, height, TRUE);
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.c b/gnome-flashback/libdesktop/gf-desktop-window.c
index 540cef8..9c573d6 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.c
+++ b/gnome-flashback/libdesktop/gf-desktop-window.c
@@ -19,13 +19,12 @@
#include "gf-desktop-window.h"
#include <gdk/gdkx.h>
-#include <libcommon/gf-background-utils.h>
-#include <libgnome-desktop/gnome-bg.h>
#include <glib/gi18n.h>
#include <X11/Xatom.h>
#include "gf-background.h"
#include "gf-icon-view.h"
+#include "libcommon/gf-bg.h"
struct _GfDesktopWindow
{
@@ -211,9 +210,9 @@ ensure_surface (GfDesktopWindow *self)
display = gtk_widget_get_display (widget);
- self->surface = gf_background_surface_get_from_root (display,
- self->width,
- self->height);
+ self->surface = gf_bg_get_surface_from_root (display,
+ self->width,
+ self->height);
gtk_widget_queue_draw (widget);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]