[Xfce4-commits] [panel-plugins/xfce4-time-out-plugin] 08/15: Copy fadeout code from xfce4-session
noreply at xfce.org
noreply at xfce.org
Fri Oct 4 05:13:43 CEST 2019
This is an automated email from the git hooks/post-receive script.
a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-time-out-plugin.
commit ed197d5eea78ef84ec4e7ddea9a678fb7720989b
Author: Andre Miranda <andreldm at xfce.org>
Date: Sat Sep 28 18:03:44 2019 -0300
Copy fadeout code from xfce4-session
---
panel-plugin/time-out-fadeout.c | 187 +++++++++++++++++++++++++---------------
panel-plugin/time-out-fadeout.h | 1 -
2 files changed, 116 insertions(+), 72 deletions(-)
diff --git a/panel-plugin/time-out-fadeout.c b/panel-plugin/time-out-fadeout.c
index 3bde599..7d36e3f 100644
--- a/panel-plugin/time-out-fadeout.c
+++ b/panel-plugin/time-out-fadeout.c
@@ -26,92 +26,143 @@
#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
-#include "time-out-fadeout.h"
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <cairo-xlib.h>
+#endif
+#include "time-out-fadeout.h"
#define COLOR "#b6c4d7"
-struct _TimeOutScreen
-{
- GdkWindow *window;
- GdkPixmap *backbuf;
-};
struct _TimeOutFadeout
{
- GdkColor color;
- GList *screens;
+#ifdef GDK_WINDOWING_X11
+ Display *xdisplay;
+ Window *xwindow;
+#endif
};
-TimeOutFadeout*
-time_out_fadeout_new (GdkDisplay *display)
+#ifdef GDK_WINDOWING_X11
+static Window
+time_out_fadeout_new_window (GdkDisplay *display,
+ GdkScreen *screen)
{
- TimeOutFadeout *fadeout;
- GdkWindowAttr attr;
- GdkGCValues values;
- GdkWindow *root;
- GdkCursor *cursor;
- TimeOutScreen *screen;
- GdkGC *gc;
- GList *iter;
- cairo_t *cr;
- gint width;
- gint height;
- gint n;
-
- fadeout = panel_slice_new0 (TimeOutFadeout);
- gdk_color_parse (COLOR, &fadeout->color);
-
- cursor = gdk_cursor_new (GDK_WATCH);
-
- attr.x = 0;
- attr.y = 0;
- attr.event_mask = 0;
- attr.wclass = GDK_INPUT_OUTPUT;
- attr.window_type = GDK_WINDOW_TEMP;
- attr.cursor = cursor;
+ XSetWindowAttributes attr;
+ Display *xdisplay;
+ Window xwindow;
+ GdkWindow *root;
+ GdkCursor *cursor;
+ cairo_t *cr;
+ gint width;
+ gint height;
+ GdkPixbuf *root_pixbuf;
+ cairo_surface_t *surface;
+ gulong mask = 0;
+ gulong opacity;
+ gboolean composited;
+ gint scale;
+
+ gdk_error_trap_push ();
+
+ xdisplay = gdk_x11_display_get_xdisplay (display);
+ root = gdk_screen_get_root_window (screen);
+
+ width = gdk_window_get_width (root);
+ height = gdk_window_get_height (root);
+
+ composited = gdk_screen_is_composited (screen)
+ && gdk_screen_get_rgba_visual (screen) != NULL;
+
+ cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
+
+ scale = gdk_window_get_scale_factor (root);
+ width *= scale;
+ height *= scale;
+
+ if (!composited)
+ {
+ /* create a copy of root window before showing the fadeout */
+ root_pixbuf = gdk_pixbuf_get_from_window (root, 0, 0, width, height);
+ }
+
+ attr.cursor = gdk_x11_cursor_get_xcursor (cursor);
+ mask |= CWCursor;
+
attr.override_redirect = TRUE;
+ mask |= CWOverrideRedirect;
- for (n = 0; n < gdk_display_get_n_screens (display); ++n)
- {
- screen = panel_slice_new0 (TimeOutScreen);
+ attr.background_pixel = BlackPixel (xdisplay, gdk_x11_screen_get_screen_number (screen));
+ mask |= CWBackPixel;
+
+ xwindow = XCreateWindow (xdisplay, gdk_x11_window_get_xid (root),
+ 0, 0, width, height, 0, CopyFromParent,
+ InputOutput, CopyFromParent, mask, &attr);
- root = gdk_screen_get_root_window (gdk_display_get_screen (display, n));
- gdk_drawable_get_size (GDK_DRAWABLE (root), &width, &height);
+ g_object_unref (cursor);
- values.function = GDK_COPY;
- values.graphics_exposures = FALSE;
- values.subwindow_mode = TRUE;
- gc = gdk_gc_new_with_values (root, &values, GDK_GC_FUNCTION | GDK_GC_EXPOSURES | GDK_GC_SUBWINDOW);
+ if (composited)
+ {
+ /* apply transparency before map */
+ opacity = 0.5 * 0xffffffff;
+ XChangeProperty (xdisplay, xwindow,
+ gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
+ XA_CARDINAL, 32, PropModeReplace, (guchar *)&opacity, 1);
+ }
- screen->backbuf = gdk_pixmap_new (GDK_DRAWABLE (root), width, height, -1);
- gdk_draw_drawable (GDK_DRAWABLE (screen->backbuf), gc, GDK_DRAWABLE (root), 0, 0, 0, 0, width, height);
+ XMapWindow (xdisplay, xwindow);
- cr = gdk_cairo_create (GDK_DRAWABLE (screen->backbuf));
- gdk_cairo_set_source_color (cr, &fadeout->color);
- cairo_paint_with_alpha (cr, 0.5);
+ if (!composited)
+ {
+ /* create background for window */
+ surface = cairo_xlib_surface_create (xdisplay, xwindow,
+ gdk_x11_visual_get_xvisual (gdk_screen_get_system_visual (screen)),
+ 0, 0);
+ cairo_xlib_surface_set_size (surface, width, height);
+ cr = cairo_create (surface);
+
+ /* draw the copy of the root window */
+ gdk_cairo_set_source_pixbuf (cr, root_pixbuf, 0, 0);
+ cairo_paint (cr);
+ g_object_unref (root_pixbuf);
+
+ /* draw black transparent layer */
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_paint (cr);
cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+ }
- attr.width = width;
- attr.height = height;
+ gdk_flush ();
+ gdk_error_trap_pop_ignored ();
- screen->window = gdk_window_new (root, &attr, GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR | GDK_WA_CURSOR);
- gdk_window_set_back_pixmap (screen->window, screen->backbuf, FALSE);
+ return xwindow;
+}
+#endif
- g_object_unref (G_OBJECT (gc));
- fadeout->screens = g_list_append (fadeout->screens, screen);
- }
- for (iter = fadeout->screens; iter != NULL; iter = g_list_next (iter))
- gdk_window_show (((TimeOutScreen *) iter->data)->window);
+TimeOutFadeout*
+time_out_fadeout_new (GdkDisplay *display)
+{
+ TimeOutFadeout *fadeout;
+ GdkScreen *screen;
- gdk_cursor_unref (cursor);
+ fadeout = g_slice_new0 (TimeOutFadeout);
+
+#ifdef GDK_WINDOWING_X11
+ fadeout->xdisplay = gdk_x11_display_get_xdisplay (display);
+ screen = gdk_display_get_default_screen (display);
+ fadeout->xwindow = GINT_TO_POINTER (time_out_fadeout_new_window (display, screen));
+#endif
return fadeout;
}
@@ -121,18 +172,12 @@ time_out_fadeout_new (GdkDisplay *display)
void
time_out_fadeout_destroy (TimeOutFadeout *fadeout)
{
- TimeOutScreen *screen;
- GList *iter;
-
- for (iter = fadeout->screens; iter != NULL; iter = g_list_next (iter))
- {
- screen = iter->data;
-
- gdk_window_destroy (screen->window);
- g_object_unref (G_OBJECT (screen->backbuf));
- panel_slice_free (TimeOutScreen, screen);
- }
+#ifdef GDK_WINDOWING_X11
+ gdk_error_trap_push ();
+ XDestroyWindow (fadeout->xdisplay, GPOINTER_TO_INT (fadeout->xwindow));
+ gdk_flush ();
+ gdk_error_trap_pop_ignored ();
+#endif
- g_list_free (fadeout->screens);
- panel_slice_free (TimeOutFadeout, fadeout);
+ g_slice_free (TimeOutFadeout, fadeout);
}
diff --git a/panel-plugin/time-out-fadeout.h b/panel-plugin/time-out-fadeout.h
index 8d71716..fbc3623 100644
--- a/panel-plugin/time-out-fadeout.h
+++ b/panel-plugin/time-out-fadeout.h
@@ -25,7 +25,6 @@
G_BEGIN_DECLS
-typedef struct _TimeOutScreen TimeOutScreen;
typedef struct _TimeOutFadeout TimeOutFadeout;
TimeOutFadeout *time_out_fadeout_new (GdkDisplay *display);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list