[gedit/zbrown/deteplification-src: 216/633] Remove X11 workspace awareness




commit fe28548f0b89ef352d26d0fe1103d0c240a0c3b0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Mar 18 17:44:52 2020 +0100

    Remove X11 workspace awareness
    
    Unfortunately workspaces information is currently not supported on
    Wayland:
    https://gitlab.gnome.org/GNOME/gtk/issues/2506
    
    And X11 is deprecated. The X11-specific code in gedit prevents gedit
    from being a native Wayland app.
    
    Fixes https://gitlab.gnome.org/GNOME/gedit/issues/177

 docs/reference/api-breaks.xml     |   8 ++
 docs/reference/gedit-sections.txt |   4 -
 gedit/gedit-app.c                 |  71 +-------------
 gedit/gedit-utils.c               | 188 --------------------------------------
 gedit/gedit-utils.h               |   9 +-
 5 files changed, 13 insertions(+), 267 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index 267f65e23..e6111ee66 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -36,6 +36,14 @@
           <code>gedit_app_get_lockdown()</code> function has been removed.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          The <code>gedit_utils_get_current_workspace()</code>,
+          <code>gedit_utils_get_window_workspace()</code> and
+          <code>gedit_utils_get_current_viewport()</code> functions have been
+          removed because workspaces information is not available on Wayland.
+        </para>
+      </listitem>
     </itemizedlist>
   </refsect1>
 
diff --git a/docs/reference/gedit-sections.txt b/docs/reference/gedit-sections.txt
index a7d2058d1..ce4f41dfd 100644
--- a/docs/reference/gedit-sections.txt
+++ b/docs/reference/gedit-sections.txt
@@ -351,15 +351,11 @@ GPOINTER_TO_BOOLEAN
 gedit_utils_menu_position_under_tree_view
 gedit_utils_set_atk_name_description
 gedit_warning
-gedit_utils_make_valid_utf8
 gedit_utils_replace_home_dir_with_tilde
-gedit_utils_get_current_workspace
-gedit_utils_get_window_workspace
 gedit_utils_basename_for_display
 gedit_utils_decode_uri
 gedit_utils_drop_get_uris
 gedit_utils_get_compression_type_from_content_type
-gedit_utils_get_current_viewport
 gedit_utils_is_valid_location
 gedit_utils_location_get_dirname_for_display
 gedit_utils_set_direct_save_filename
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 758c944f9..ecdccb370 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -267,82 +267,19 @@ gedit_app_set_window_title_impl (GeditApp    *app,
        gtk_window_set_title (GTK_WINDOW (window), title);
 }
 
-static gboolean
-is_in_viewport (GtkWindow    *window,
-               GdkScreen    *screen,
-               gint          workspace,
-               gint          viewport_x,
-               gint          viewport_y)
-{
-       GdkScreen *s;
-       GdkDisplay *display;
-       GdkMonitor *monitor;
-       GdkWindow *gdkwindow;
-       GdkRectangle geometry;
-       const gchar *cur_name;
-       const gchar *name;
-       gint ws;
-       gint x, y, width, height;
-
-       /* Check for screen and display match */
-       display = gdk_screen_get_display (screen);
-       cur_name = gdk_display_get_name (display);
-
-       s = gtk_window_get_screen (window);
-       display = gdk_screen_get_display (s);
-       name = gdk_display_get_name (display);
-
-       if (strcmp (cur_name, name) != 0)
-       {
-               return FALSE;
-       }
-
-       /* Check for workspace match */
-       ws = gedit_utils_get_window_workspace (window);
-
-       if (ws != workspace && ws != GEDIT_ALL_WORKSPACES)
-       {
-               return FALSE;
-       }
-
-       /* Check for viewport match */
-       gdkwindow = gtk_widget_get_window (GTK_WIDGET (window));
-       gdk_window_get_position (gdkwindow, &x, &y);
-       width = gdk_window_get_width (gdkwindow);
-       height = gdk_window_get_height (gdkwindow);
-
-       x += viewport_x;
-       y += viewport_y;
-
-       monitor = gdk_display_get_monitor_at_window(display, gdkwindow);
-       gdk_monitor_get_geometry(monitor, &geometry);
-
-       return x + width * .75 >= geometry.x &&
-              x + width * .25 <= geometry.x + geometry.width &&
-              y + height * .75 >= geometry.y &&
-              y + height * .25 <= geometry.y + geometry.height;
-}
-
 static GeditWindow *
 get_active_window (GtkApplication *app)
 {
-       GdkScreen *screen;
-       guint workspace;
-       gint viewport_x, viewport_y;
-       GList *windows, *l;
-
-       screen = gdk_screen_get_default ();
-
-       workspace = gedit_utils_get_current_workspace (screen);
-       gedit_utils_get_current_viewport (screen, &viewport_x, &viewport_y);
+       GList *windows;
+       GList *l;
 
-       /* Gtk documentation says the window list is always in MRU order */
+       /* Gtk documentation says the window list is always in MRU order. */
        windows = gtk_application_get_windows (app);
        for (l = windows; l != NULL; l = l->next)
        {
                GtkWindow *window = l->data;
 
-               if (GEDIT_IS_WINDOW (window) && is_in_viewport (window, screen, workspace, viewport_x, 
viewport_y))
+               if (GEDIT_IS_WINDOW (window))
                {
                        return GEDIT_WINDOW (window);
                }
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 23bf91e6c..f1a5c571b 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -21,16 +21,8 @@
  */
 
 #include "gedit-utils.h"
-
 #include <string.h>
 #include <glib/gi18n.h>
-
-/* For the workspace/viewport stuff */
-#ifdef GDK_WINDOWING_X11
-#include <gdk/gdkx.h>
-#include <X11/Xatom.h>
-#endif
-
 #include "gedit-debug.h"
 
 gboolean
@@ -355,186 +347,6 @@ gedit_utils_replace_home_dir_with_tilde (const gchar *uri)
        return g_strdup (uri);
 }
 
-/* the following two functions are courtesy of galeon */
-
-/**
- * gedit_utils_get_current_workspace:
- * @screen: a #GdkScreen
- *
- * Get the currently visible workspace for the #GdkScreen.
- *
- * If the X11 window property isn't found, 0 (the first workspace)
- * is returned.
- */
-guint
-gedit_utils_get_current_workspace (GdkScreen *screen)
-{
-#ifdef GDK_WINDOWING_X11
-       GdkWindow *root_win;
-       GdkDisplay *display;
-       guint ret = 0;
-
-       g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
-
-       root_win = gdk_screen_get_root_window (screen);
-       display = gdk_screen_get_display (screen);
-
-       if (GDK_IS_X11_DISPLAY (display))
-       {
-               Atom type;
-               gint format;
-               gulong nitems;
-               gulong bytes_after;
-               guint *current_desktop;
-               gint err, result;
-
-               gdk_x11_display_error_trap_push (display);
-               result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
-                                            gdk_x11_get_xatom_by_name_for_display (display, 
"_NET_CURRENT_DESKTOP"),
-                                            0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
-                                            &bytes_after, (gpointer) &current_desktop);
-               err = gdk_x11_display_error_trap_pop (display);
-
-               if (err != Success || result != Success)
-                       return ret;
-
-               if (type == XA_CARDINAL && format == 32 && nitems > 0)
-                       ret = current_desktop[0];
-
-               XFree (current_desktop);
-       }
-
-       return ret;
-#else
-       /* FIXME: on mac etc proably there are native APIs
-        * to get the current workspace etc */
-       return 0;
-#endif
-}
-
-/**
- * gedit_utils_get_window_workspace:
- * @gtkwindow: a #GtkWindow.
- *
- * Get the workspace the window is on.
- *
- * This function gets the workspace that the #GtkWindow is visible on,
- * it returns GEDIT_ALL_WORKSPACES if the window is sticky, or if
- * the window manager doesn't support this function.
- *
- * Returns: the workspace the window is on.
- */
-guint
-gedit_utils_get_window_workspace (GtkWindow *gtkwindow)
-{
-#ifdef GDK_WINDOWING_X11
-       GdkWindow *window;
-       GdkDisplay *display;
-       Atom type;
-       gint format;
-       gulong nitems;
-       gulong bytes_after;
-       guint *workspace;
-       gint err, result;
-       guint ret = GEDIT_ALL_WORKSPACES;
-
-       g_return_val_if_fail (GTK_IS_WINDOW (gtkwindow), 0);
-       g_return_val_if_fail (gtk_widget_get_realized (GTK_WIDGET (gtkwindow)), 0);
-
-       window = gtk_widget_get_window (GTK_WIDGET (gtkwindow));
-       display = gdk_window_get_display (window);
-
-       if (GDK_IS_X11_DISPLAY (display))
-       {
-               gdk_x11_display_error_trap_push (display);
-               result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
-                                            gdk_x11_get_xatom_by_name_for_display (display, 
"_NET_WM_DESKTOP"),
-                                            0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
-                                            &bytes_after, (gpointer) &workspace);
-               err = gdk_x11_display_error_trap_pop (display);
-
-               if (err != Success || result != Success)
-                       return ret;
-
-               if (type == XA_CARDINAL && format == 32 && nitems > 0)
-                       ret = workspace[0];
-
-               XFree (workspace);
-       }
-
-       return ret;
-#else
-       /* FIXME: on mac etc proably there are native APIs
-        * to get the current workspace etc */
-       return 0;
-#endif
-}
-
-/**
- * gedit_utils_get_current_viewport:
- * @screen: a #GdkScreen
- * @x: (out): x-axis point.
- * @y: (out): y-axis point.
- *
- * Get the currently visible viewport origin for the #GdkScreen.
- *
- * If the X11 window property isn't found, (0, 0) is returned.
- */
-void
-gedit_utils_get_current_viewport (GdkScreen    *screen,
-                                 gint         *x,
-                                 gint         *y)
-{
-#ifdef GDK_WINDOWING_X11
-       GdkWindow *root_win;
-       GdkDisplay *display;
-       Atom type;
-       gint format;
-       gulong nitems;
-       gulong bytes_after;
-       gulong *coordinates;
-       gint err, result;
-
-       g_return_if_fail (GDK_IS_SCREEN (screen));
-       g_return_if_fail (x != NULL && y != NULL);
-
-       /* Default values for the viewport origin */
-       *x = 0;
-       *y = 0;
-
-       root_win = gdk_screen_get_root_window (screen);
-       display = gdk_screen_get_display (screen);
-
-       if (GDK_IS_X11_DISPLAY (display))
-       {
-               gdk_x11_display_error_trap_push (display);
-               result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
-                                            gdk_x11_get_xatom_by_name_for_display (display, 
"_NET_DESKTOP_VIEWPORT"),
-                                            0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
-                                            &bytes_after, (void*) &coordinates);
-               err = gdk_x11_display_error_trap_pop (display);
-
-               if (err != Success || result != Success)
-                       return;
-
-               if (type != XA_CARDINAL || format != 32 || nitems < 2)
-               {
-                       XFree (coordinates);
-                       return;
-               }
-
-               *x = coordinates[0];
-               *y = coordinates[1];
-               XFree (coordinates);
-       }
-#else
-       /* FIXME: on mac etc proably there are native APIs
-        * to get the current workspace etc */
-       *x = 0;
-       *y = 0;
-#endif
-}
-
 static gboolean
 is_valid_scheme_character (gchar c)
 {
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index 88130fc60..89c42e9fd 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -31,8 +31,6 @@ G_BEGIN_DECLS
 #define GBOOLEAN_TO_POINTER(i) (GINT_TO_POINTER ((i) ? 2 : 1))
 #define GPOINTER_TO_BOOLEAN(i) ((gboolean) ((GPOINTER_TO_INT(i) == 2) ? TRUE : FALSE))
 
-enum { GEDIT_ALL_WORKSPACES = 0xffffffff };
-
 gboolean                   gedit_utils_menu_position_under_tree_view          (GtkTreeView     *tree_view,
                                                                                GdkRectangle    *rect);
 
@@ -49,13 +47,8 @@ void                       gedit_warning                                       (
 
 gchar                     *gedit_utils_location_get_dirname_for_display        (GFile          *location);
 gchar                     *gedit_utils_replace_home_dir_with_tilde             (const gchar    *uri);
-guint                      gedit_utils_get_current_workspace                   (GdkScreen      *screen);
-guint                      gedit_utils_get_window_workspace                    (GtkWindow      *gtkwindow);
-void                       gedit_utils_get_current_viewport                    (GdkScreen      *screen,
-                                                                                gint           *x,
-                                                                                gint           *y);
-gboolean                   gedit_utils_is_valid_location                       (GFile          *location);
 
+gboolean                   gedit_utils_is_valid_location                       (GFile          *location);
 
 gchar                     *gedit_utils_basename_for_display                   (GFile        *location);
 gboolean                   gedit_utils_decode_uri                             (const gchar  *uri,


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