"Fossies" - the Fresh Open Source Software Archive

Member "mono-6.12.0.122/external/bockbuild/packages/patches/gtk/0078-Optimize-querying-symbolic-hotkeys.patch" (22 Feb 2021, 2449 Bytes) of package /linux/misc/mono-sources/mono/mono-6.12.0.122.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Diff source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 From ba68d11840da0ea10b863c598b1947fa1090a557 Mon Sep 17 00:00:00 2001
    2 From: Marius Ungureanu <maungu@microsoft.com>
    3 Date: Wed, 2 Dec 2020 17:39:31 +0200
    4 Subject: [PATCH] Optimize querying symbolic hotkeys
    5 
    6 This API is not threadsafe and there is no alternative API for querying
    7 whether the symbolic hotkeys have changed.
    8 
    9 Instead, we can check the last modification time of the preferences file
   10 and only update the symbolic hotkeys _iff_ the underlying storage file
   11 has changed.
   12 ---
   13  gdk/quartz/gdkkeys-quartz.c | 40 +++++++++++++++++++++++++++++++++++--
   14  1 file changed, 38 insertions(+), 2 deletions(-)
   15 
   16 diff --git a/gdk/quartz/gdkkeys-quartz.c b/gdk/quartz/gdkkeys-quartz.c
   17 index 5a4d88787d..8ee8628dd2 100644
   18 --- a/gdk/quartz/gdkkeys-quartz.c
   19 +++ b/gdk/quartz/gdkkeys-quartz.c
   20 @@ -58,6 +58,8 @@
   21  #include "gdkprivate-quartz.h"
   22  #include <Foundation/Foundation.h>
   23  
   24 +#include <glib/gstdio.h>
   25 +
   26  #define NUM_KEYCODES 128
   27  #define KEYVALS_PER_KEYCODE 4
   28  
   29 @@ -68,6 +70,7 @@ static GdkKeymap *default_keymap = NULL;
   30   */
   31  static guint *keyval_array = NULL;
   32  static CFArrayRef global_hotkeys = NULL;
   33 +static struct timespec preferences_last_mtime = {};
   34  
   35  static inline UniChar
   36  macroman2ucs (unsigned char c)
   37 @@ -815,12 +818,45 @@ gdk_keymap_map_virtual_modifiers (GdkKeymap       *keymap,
   38    return TRUE;
   39  }
   40  
   41 +static gboolean
   42 +should_update_symbolic_hotkeys ()
   43 +{
   44 +  gchar *path_segments[] = {
   45 +    g_get_home_dir(),
   46 +    "Library",
   47 +    "Preferences",
   48 +    "com.apple.symbolichotkeys.plist",
   49 +    NULL,
   50 +  };
   51 +
   52 +  gchar *preferences_file = g_build_pathv(G_DIR_SEPARATOR_S, path_segments);
   53 +  GStatBuf buf;
   54 +
   55 +  int res = g_stat(preferences_file, &buf);
   56 +  g_free(preferences_file);
   57 +
   58 +  if (res != 0) {
   59 +    /* In case we have any IO error, ensure correctness by querying */
   60 +    return TRUE;
   61 +  }
   62 +
   63 +  bool preferences_file_modified = preferences_last_mtime.tv_sec != buf.st_mtimespec.tv_sec
   64 +    && preferences_last_mtime.tv_nsec != buf.st_mtimespec.tv_nsec;
   65 +
   66 +  preferences_last_mtime.tv_sec = buf.st_mtimespec.tv_sec;
   67 +  preferences_last_mtime.tv_nsec = buf.st_mtimespec.tv_nsec;
   68 +
   69 +  return preferences_file_modified;
   70 +}
   71 +
   72  void
   73  _gdk_quartz_update_symbolic_hotkeys ()
   74  {
   75 -  _gdk_quartz_release_symbolic_hotkeys ();
   76 +  if (should_update_symbolic_hotkeys ()) {
   77 +    _gdk_quartz_release_symbolic_hotkeys ();
   78  
   79 -  CopySymbolicHotKeys (&global_hotkeys);
   80 +    CopySymbolicHotKeys (&global_hotkeys);
   81 +  }
   82  }
   83  
   84  void
   85 -- 
   86 2.21.1 (Apple Git-122.3)
   87