Re: [PATCH vdagent v2 2/2] retrieve _NET_WM_NAME using GDK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> String returned by gdk_x11_screen_get_window_manager_name()
> is never NULL. If the name cannot be retrieved, "unknown" is returned.
> Change in logging behavior:
> If debug flag is specified, _NET_WM_NAME is always logged
> (either the actual name or "unknown").
> ---
>  src/vdagent/x11-priv.h |  2 +-
>  src/vdagent/x11.c      | 75
>  ++++++++++----------------------------------------
>  2 files changed, 15 insertions(+), 62 deletions(-)
> 
> diff --git a/src/vdagent/x11-priv.h b/src/vdagent/x11-priv.h
> index 677a44d..a7f9f14 100644
> --- a/src/vdagent/x11-priv.h
> +++ b/src/vdagent/x11-priv.h
> @@ -87,7 +87,7 @@ struct vdagent_x11 {
>      Window root_window[MAX_SCREENS];
>      Window selection_window;
>      struct udscs_connection *vdagentd;
> -    char *net_wm_name;
> +    const char *net_wm_name;
>      int debug;
>      int fd;
>      int screen_count;
> diff --git a/src/vdagent/x11.c b/src/vdagent/x11.c
> index 6e47ea1..736d1ea 100644
> --- a/src/vdagent/x11.c
> +++ b/src/vdagent/x11.c
> @@ -32,6 +32,10 @@
>     pending writes are flushed. */
>  
>  #include <glib.h>
> +#include <gdk/gdk.h>
> +#ifdef GDK_WINDOWING_X11
> +#include <gdk/gdkx.h>
> +#endif
>  #include <stdlib.h>
>  #include <limits.h>
>  #include <string.h>
> @@ -113,64 +117,14 @@ int vdagent_x11_restore_error_handler(struct
> vdagent_x11 *x11)
>  
>  static void vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
>  {
> -    Atom type_ret;
> -    int format_ret;
> -    unsigned long len, remain;
> -    unsigned char *data = NULL;
> -    Window sup_window = None;
> -
> -    /* XGetWindowProperty can throw a BadWindow error. One way we can
> trigger
> -       this is when the display-manager (ie gdm) has set, and not cleared
> the
> -       _NET_SUPPORTING_WM_CHECK property, and the window manager running in
> -       the user session has not yet updated it to point to its window, so
> its
> -       pointing to a nonexistent window. */
> -    vdagent_x11_set_error_handler(x11,
> vdagent_x11_ignore_bad_window_handler);
> -
> -    /* Get the window manager SUPPORTING_WM_CHECK window */
> -    if (XGetWindowProperty(x11->display, x11->root_window[0],
> -            XInternAtom(x11->display, "_NET_SUPPORTING_WM_CHECK", False), 0,
> -            LONG_MAX, False, XA_WINDOW, &type_ret, &format_ret, &len,
> -            &remain, &data) == Success) {
> -        if (type_ret == XA_WINDOW)
> -            sup_window = *((Window *)data);
> -        XFree(data);
> -    }
> -    if (sup_window == None &&
> -        XGetWindowProperty(x11->display, x11->root_window[0],
> -            XInternAtom(x11->display, "_WIN_SUPPORTING_WM_CHECK", False), 0,
> -            LONG_MAX, False, XA_CARDINAL, &type_ret, &format_ret, &len,
> -            &remain, &data) == Success) {
> -        if (type_ret == XA_CARDINAL)
> -            sup_window = *((Window *)data);
> -        XFree(data);
> -    }
> -    /* So that we can get the net_wm_name */
> -    if (sup_window != None) {
> -        Atom utf8 = XInternAtom(x11->display, "UTF8_STRING", False);
> -        if (XGetWindowProperty(x11->display, sup_window,
> -                XInternAtom(x11->display, "_NET_WM_NAME", False), 0,
> -                LONG_MAX, False, utf8, &type_ret, &format_ret, &len,
> -                &remain, &data) == Success) {
> -            if (type_ret == utf8) {
> -                x11->net_wm_name =
> -                    g_strndup((char *)data, (format_ret / 8) * len);
> -            }
> -            XFree(data);
> -        }
> -        if (x11->net_wm_name == NULL &&
> -            XGetWindowProperty(x11->display, sup_window,
> -                XInternAtom(x11->display, "_NET_WM_NAME", False), 0,
> -                LONG_MAX, False, XA_STRING, &type_ret, &format_ret, &len,
> -                &remain, &data) == Success) {
> -            if (type_ret == XA_STRING) {
> -                x11->net_wm_name =
> -                    g_strndup((char *)data, (format_ret / 8) * len);
> -            }
> -            XFree(data);
> -        }
> -    }
> -
> -    vdagent_x11_restore_error_handler(x11);
> +#ifdef GDK_WINDOWING_X11
> +    GdkDisplay *display = gdk_display_get_default();
> +    if (GDK_IS_X11_DISPLAY(display))
> +        x11->net_wm_name = gdk_x11_screen_get_window_manager_name(
> +            gdk_display_get_default_screen(display));
> +    else
> +#endif
> +    x11->net_wm_name = "unknown";
>  }
>  
>  struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
> @@ -279,11 +233,11 @@ struct vdagent_x11 *vdagent_x11_create(struct
> udscs_connection *vdagentd,
>         sometimes we need to wait a bit for it to show up. */
>      i = 10;
>      vdagent_x11_get_wm_name(x11);
> -    while (x11->net_wm_name == NULL && --i > 0) {
> +    while (!strcmp(x11->net_wm_name, "unknown") && --i > 0) {
>          usleep(100000);
>          vdagent_x11_get_wm_name(x11);
>      }
> -    if (x11->debug && x11->net_wm_name)
> +    if (x11->debug)
>          syslog(LOG_DEBUG, "net_wm_name: \"%s\", has icons: %d",
>                 x11->net_wm_name, vdagent_x11_has_icons_on_desktop(x11));
>  
> @@ -308,7 +262,6 @@ void vdagent_x11_destroy(struct vdagent_x11 *x11, int
> vdagentd_disconnected)
>      }
>  
>      XCloseDisplay(x11->display);
> -    g_free(x11->net_wm_name);
>      free(x11->randr.failed_conf);
>      free(x11);
>  }

One doubt about gdk_x11_screen_get_window_manager_name, the life of the
result. The documentation states "Returns: the name of the window manager
screen screen , or "unknown" if the window manager is unknown. The string
 is owned by GDK and should not be freed.". Ok, we cannot free it but how
long will this pointer last? Potentially I can kill the window manager and
launch another. What will happen in this case? Will be the old pointer
still valid? Or will be a dandling one?
Without this patch we copy the property in a new buffer so we are sure
that our buffer will be alive when we access it.

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]