[Xfce4-commits] [xfce/xfce4-session] 04/04: Fix fadeout window using Xlib API
noreply at xfce.org
noreply at xfce.org
Thu Dec 7 08:01:26 CET 2017
This is an automated email from the git hooks/post-receive script.
e r i c 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 xfce/xfce4-session.
commit 1be6d6a24dd295016780c7c97100d4500aadad65
Author: Viktor Odintsev <ninetls at xfce.org>
Date: Tue Dec 5 16:03:47 2017 +0300
Fix fadeout window using Xlib API
Windows with override_redirect == TRUE have a different behavior
starting with GDK 3. This part of code was rewritten with Xlib API.
Signed-off-by: Eric Koegel <eric.koegel at gmail.com>
---
libxfsm/xfsm-util.c | 12 ++-
xfce4-session/xfsm-fadeout.c | 208 +++++++++++++++++++++++--------------
xfce4-session/xfsm-fadeout.h | 1 -
xfce4-session/xfsm-logout-dialog.c | 4 -
4 files changed, 141 insertions(+), 84 deletions(-)
diff --git a/libxfsm/xfsm-util.c b/libxfsm/xfsm-util.c
index f8809e3..537aab0 100644
--- a/libxfsm/xfsm-util.c
+++ b/libxfsm/xfsm-util.c
@@ -157,7 +157,12 @@ void
xfsm_window_add_border (GtkWindow *window)
{
GtkWidget *box1, *box2;
- GdkRGBA bg_color;
+ GtkWidget *child;
+ GdkRGBA bg_color;
+
+ child = gtk_bin_get_child (GTK_BIN (window));
+ if (G_UNLIKELY (child == NULL))
+ return;
gtk_widget_realize(GTK_WIDGET(window));
@@ -176,9 +181,12 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gtk_container_add (GTK_CONTAINER (box1), box2);
gtk_container_set_border_width (GTK_CONTAINER (box2), 6);
- gtk_container_add (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (window))), box2);
+ g_object_ref (child);
+ gtk_container_remove (GTK_CONTAINER (window), child);
gtk_container_add (GTK_CONTAINER (window), box1);
+ gtk_container_add (GTK_CONTAINER (box2), child);
+ g_object_unref (child);
}
XfconfChannel*
diff --git a/xfce4-session/xfsm-fadeout.c b/xfce4-session/xfsm-fadeout.c
index 8102acf..6233fa2 100644
--- a/xfce4-session/xfsm-fadeout.c
+++ b/xfce4-session/xfsm-fadeout.c
@@ -24,117 +24,171 @@
#endif
#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
#include <xfce4-session/xfsm-fadeout.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <cairo-xlib.h>
+#endif
+
struct _XfsmFadeout
{
- GSList *windows;
+#ifdef GDK_WINDOWING_X11
+ Display *xdisplay;
+ GSList *xwindows;
+#endif
};
+#ifdef GDK_WINDOWING_X11
+static Window
+xfsm_x11_fadeout_new_window (GdkDisplay *display,
+ GdkScreen *screen)
+{
+ 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;
+
+ 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);
+
+ 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;
+
+ 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);
+
+ g_object_unref (cursor);
+
+ 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);
+ }
+
+ XMapWindow (xdisplay, xwindow);
+
+ 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);
+ }
+
+ gdk_flush ();
+ gdk_error_trap_pop_ignored ();
+
+ return xwindow;
+}
+#endif
+
+
+
XfsmFadeout*
xfsm_fadeout_new (GdkDisplay *display)
{
- GdkWindowAttr attr;
XfsmFadeout *fadeout;
- GdkWindow *root;
- GdkCursor *cursor;
- cairo_t *cr;
- gint width;
- gint height;
+ GdkScreen *screen;
+#ifdef GDK_WINDOWING_X11
+ Window xwindow;
+#endif
gint n;
- GdkPixbuf *root_pixbuf;
- cairo_surface_t *surface;
- GdkScreen *gdk_screen;
- GdkWindow *window;
- GdkRGBA black = { 0, };
fadeout = g_slice_new0 (XfsmFadeout);
- cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
+#ifdef GDK_WINDOWING_X11
+ fadeout->xdisplay = gdk_x11_display_get_xdisplay (display);
- attr.x = 0;
- attr.y = 0;
- attr.event_mask = 0;
- attr.wclass = GDK_INPUT_OUTPUT;
- attr.window_type = GDK_WINDOW_TEMP;
- attr.cursor = cursor;
- attr.override_redirect = TRUE;
-
- for (n = 0; n < XScreenCount (gdk_x11_display_get_xdisplay ((display))); ++n)
+ for (n = 0; n < XScreenCount (fadeout->xdisplay); ++n)
{
- gdk_screen = gdk_display_get_screen (display, n);
-
- root = gdk_screen_get_root_window (gdk_screen);
-
- width = gdk_window_get_width (root);
- height = gdk_window_get_height (root);
-
- attr.width = width;
- attr.height = height;
- window = gdk_window_new (root, &attr, GDK_WA_X | GDK_WA_Y
- | GDK_WA_NOREDIR | GDK_WA_CURSOR);
-
- if (gdk_screen_is_composited (gdk_screen)
- && gdk_screen_get_rgba_visual (gdk_screen) != NULL)
- {
- /* transparent black window */
- gdk_window_set_background_rgba (window, &black);
- gdk_window_set_opacity (window, 0.50);
- }
- else
- {
- /* create background for window */
- surface = gdk_window_create_similar_surface (root, CAIRO_CONTENT_COLOR_ALPHA, width, height);
- cr = cairo_create (surface);
-
- /* make of copy of the root window */
- root_pixbuf = gdk_pixbuf_get_from_window (root, 0, 0, width, height);
- gdk_cairo_set_source_pixbuf (cr, root_pixbuf, 0, 0);
- cairo_paint (cr);
- g_object_unref (G_OBJECT (root_pixbuf));
-
- /* draw black layer */
- gdk_cairo_set_source_rgba (cr, &black);
- cairo_paint_with_alpha (cr, 0.50);
- cairo_destroy (cr);
- cairo_surface_destroy (surface);
- }
-
- fadeout->windows = g_slist_prepend (fadeout->windows, window);
+ screen = gdk_display_get_screen (display, n);
+ xwindow = xfsm_x11_fadeout_new_window (display, screen);
+ fadeout->xwindows = g_slist_prepend (fadeout->xwindows, GINT_TO_POINTER (xwindow));
}
-
- /* show all windows all at once */
- g_slist_foreach (fadeout->windows, (GFunc) gdk_window_show, NULL);
-
- g_object_unref (cursor);
+#endif
return fadeout;
}
-void
-xfsm_fadeout_clear (XfsmFadeout *fadeout)
+#ifdef GDK_WINDOWING_X11
+static void
+xfsm_fadeout_destroy_foreach (gpointer data, gpointer user_data)
{
-/* TODO: Test if this is needed.
- if (fadeout != NULL)
- g_slist_foreach (fadeout->windows, (GFunc) gdk_window_clear, NULL);
- */
+ XfsmFadeout *fadeout = user_data;
+ Window xwindow = GPOINTER_TO_INT (data);
+
+ XDestroyWindow (fadeout->xdisplay, xwindow);
}
+#endif
void
xfsm_fadeout_destroy (XfsmFadeout *fadeout)
{
- g_slist_foreach (fadeout->windows, (GFunc) gdk_window_hide, NULL);
- g_slist_foreach (fadeout->windows, (GFunc) gdk_window_destroy, NULL);
-
- g_slist_free (fadeout->windows);
+#ifdef GDK_WINDOWING_X11
+ gdk_error_trap_push ();
+ g_slist_foreach (fadeout->xwindows, xfsm_fadeout_destroy_foreach, fadeout);
+ gdk_flush ();
+ gdk_error_trap_pop_ignored ();
+#endif
+
g_slice_free (XfsmFadeout, fadeout);
}
diff --git a/xfce4-session/xfsm-fadeout.h b/xfce4-session/xfsm-fadeout.h
index 6cc80fe..9b31af2 100644
--- a/xfce4-session/xfsm-fadeout.h
+++ b/xfce4-session/xfsm-fadeout.h
@@ -30,7 +30,6 @@ G_BEGIN_DECLS;
typedef struct _XfsmFadeout XfsmFadeout;
XfsmFadeout *xfsm_fadeout_new (GdkDisplay *display);
-void xfsm_fadeout_clear (XfsmFadeout *fadeout);
void xfsm_fadeout_destroy (XfsmFadeout *fadeout);
G_END_DECLS;
diff --git a/xfce4-session/xfsm-logout-dialog.c b/xfce4-session/xfsm-logout-dialog.c
index 4871f62..2fab489 100644
--- a/xfce4-session/xfsm-logout-dialog.c
+++ b/xfce4-session/xfsm-logout-dialog.c
@@ -102,8 +102,6 @@ struct _XfsmLogoutDialog
/* dialog buttons */
GtkWidget *button_cancel;
- GtkWidget *button_ok;
- GtkWidget *button_close;
/* error label */
GtkWidget *error_label;
@@ -469,7 +467,6 @@ xfsm_logout_dialog_set_mode (XfsmLogoutDialog *dialog,
gtk_widget_set_visible (dialog->box[i], i == mode);
gtk_widget_set_visible (dialog->button_cancel, mode != MODE_SHOW_ERROR);
- gtk_widget_set_visible (dialog->button_close, mode == MODE_SHOW_ERROR);
}
@@ -820,7 +817,6 @@ xfsm_logout_dialog (const gchar *session_name,
/* display fadeout */
fadeout = xfsm_fadeout_new (gdk_screen_get_display (screen));
- gdk_flush ();
dialog = g_object_new (XFSM_TYPE_LOGOUT_DIALOG,
"type", GTK_WINDOW_POPUP,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list