Re: binding keys to actions without gconf



On Wed, 2006-05-10 at 09:05 -0600, Elijah Newren wrote:
> On 5/10/06, Seb James <seb esfnet co uk> wrote:
> > Hi List,
> >
> > I've built metacity 2.8.13 without gconf which runs very well.
> >
> > Is there any mechanism in metacity for capturing and acting on key
> > presses? I don't think there is, but I just wanted to be sure.
> 
> Well, enabling gconf is the obvious one.  ;-)  Without gconf though,
> there are (at least) two ways to get keybindings to work in metacity:
> 
> (1) Upgrade to metacity 2.14.x
> (2) Backport the relevant code to metacity 2.8.13 (see bug 326661).

Here's the diff of prefs.c after backporting the patch in bug 326661 to
metacity 2.8.13.

regards,

Seb James

-- 
Embedded Software Foundry Ltd. 'Embedded Linux Development'
Tel: +44 (0)845 4580277   Web: http://www.esfnet.co.uk/
Axiom Tech Open Source Member: http://www.axiomtech.co.uk/
Gpg key: http://www.esfnet.co.uk/ssl/seb.gpg


--- metacity-2.8.13/src/prefs.c	2005-02-19 22:52:13.000000000 +0000
+++ metacity-2.8.13_esf/src/prefs.c	2006-05-11 11:37:11.000000000 +0100
@@ -29,7 +29,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-#define MAX_REASONABLE_WORKSPACES 36
+#define MAX_REASONABLE_WORKSPACES 4
 
 #define MAX_COMMANDS (32 + NUM_EXTRA_COMMANDS)
 #define NUM_EXTRA_COMMANDS 2
@@ -70,14 +70,14 @@
 #endif
 static GList *listeners = NULL;
 
-static gboolean use_system_font = TRUE;
+static gboolean use_system_font = FALSE;
 static PangoFontDescription *titlebar_font = NULL;
 static MetaVirtualModifier mouse_button_mods = Mod1Mask;
 static MetaFocusMode focus_mode = META_FOCUS_MODE_CLICK;
-static char* current_theme = NULL;
-static int num_workspaces = 4;
+static char* current_theme = "Nuvola";
+static int num_workspaces = 1;
 static MetaActionDoubleClickTitlebar action_double_click_titlebar =
-    META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_SHADE;
+    META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_MAXIMIZE;
 static gboolean application_based = FALSE;
 static gboolean disable_workarounds = FALSE;
 static gboolean auto_raise = FALSE;
@@ -105,10 +105,10 @@
 /* The screenshot commands are at the end */
 static char *commands[MAX_COMMANDS] = { NULL, };
 
-static char *workspace_names[MAX_REASONABLE_WORKSPACES] = { NULL, };
+static char *workspace_names[MAX_REASONABLE_WORKSPACES] = { "sumo" };
 
 #ifdef HAVE_GCONF
-static gboolean update_use_system_font   (gboolean    value);
+static gboolean update_use_system_font    (gboolean    value);
 static gboolean update_titlebar_font      (const char *value);
 static gboolean update_mouse_button_mods  (const char *value);
 static gboolean update_focus_mode         (const char *value);
@@ -126,8 +126,6 @@
                                            const char *value);
 static gboolean update_screen_binding     (const char *name,
                                            const char *value);
-static gboolean update_binding            (MetaKeyPref *binding,
-                                           const char  *value);
 static gboolean update_command            (const char  *name,
                                            const char  *value);
 static gboolean update_workspace_name     (const char  *name,
@@ -143,6 +141,8 @@
 
 static void queue_changed (MetaPreference  pref);
 #endif /* HAVE_GCONF */
+static gboolean update_binding            (MetaKeyPref *binding,
+                                           const char  *value);
 
 static void     init_bindings             (void);
 static void     init_commands             (void);
@@ -929,7 +929,6 @@
 
   return (visual_bell_type != old_bell_type);
 }
-#endif /* HAVE_GCONF */
 
 static gboolean
 update_visual_bell (gboolean visual_bell, gboolean audible_bell)
@@ -945,6 +944,7 @@
 
   return has_changed;
 }
+#endif /* HAVE_GCONF */
 
 #ifdef HAVE_GCONF
 static gboolean
@@ -1497,6 +1497,52 @@
   { NULL, 0, 0, FALSE }
 };
 
+#ifndef HAVE_GCONF
+typedef struct
+{
+  const char *name;
+  const char *keybinding;
+} MetaSimpleKeyMapping;
+
+/* Name field must occur in the same order as screen_bindings, though entries
+ * can be skipped
+ */
+static MetaSimpleKeyMapping screen_string_bindings[] = {
+  { META_KEYBINDING_WORKSPACE_LEFT,         "<Control><Alt>Left"         },
+  { META_KEYBINDING_WORKSPACE_RIGHT,        "<Control><Alt>Right"        },
+  { META_KEYBINDING_WORKSPACE_UP,           "<Control><Alt>Up"           },
+  { META_KEYBINDING_WORKSPACE_DOWN,         "<Control><Alt>Down"         },
+  { META_KEYBINDING_SWITCH_WINDOWS,         "<Alt>Tab"                   },
+  { META_KEYBINDING_SWITCH_PANELS,          "<Control><Alt>Tab"          },
+  { META_KEYBINDING_CYCLE_WINDOWS,          "<Alt>Escape"                },
+  { META_KEYBINDING_CYCLE_PANELS,           "<Control><Alt>Escape"       },
+  { META_KEYBINDING_SHOW_DESKTOP,           "<Control><Alt>d"            },
+  { META_KEYBINDING_PANEL_MAIN_MENU,        "<Alt>F1"                    },
+  { META_KEYBINDING_PANEL_RUN_DIALOG,       "<Alt>F2"                    },
+  { META_KEYBINDING_COMMAND_SCREENSHOT,     "Print"                      },
+  { META_KEYBINDING_COMMAND_WIN_SCREENSHOT, "<Alt>Print"                 },
+  { NULL,                                   NULL                         }
+};
+
+/* Name field must occur in the same order as window_bindings, though entries
+ * can be skipped
+ */
+static MetaSimpleKeyMapping window_string_bindings[] = {
+  { META_KEYBINDING_WINDOW_MENU,            "<Alt>Print"                 },
+  { META_KEYBINDING_MAXIMIZE,               "<Alt>F10"                   },
+  { META_KEYBINDING_UNMAXIMIZE,             "<Alt>F5"                    },
+  { META_KEYBINDING_MINIMIZE,               "<Alt>F9"                    },
+  { META_KEYBINDING_CLOSE,                  "<Alt>F4"                    },
+  { META_KEYBINDING_BEGIN_MOVE,             "<Alt>F7"                    },
+  { META_KEYBINDING_BEGIN_RESIZE,           "<Alt>F8"                    },
+  { META_KEYBINDING_MOVE_WORKSPACE_LEFT,    "<Control><Shift><Alt>Left"  },
+  { META_KEYBINDING_MOVE_WORKSPACE_RIGHT,   "<Control><Shift><Alt>Right" },
+  { META_KEYBINDING_MOVE_WORKSPACE_UP,      "<Control><Shift><Alt>Up"    },
+  { META_KEYBINDING_MOVE_WORKSPACE_DOWN,    "<Control><Shift><Alt>Down"  },
+  { NULL,                                   NULL                         }
+};
+#endif /* NOT HAVE_GCONF */
+
 static void
 init_bindings (void)
 {
@@ -1545,6 +1591,42 @@
 
       ++i;
     }
+#else /* HAVE_GCONF */
+  int i = 0;
+  int which = 0;
+  while (window_string_bindings[i].name)
+    {
+      /* Find which window_bindings entry this window_string_bindings entry
+       * corresponds to.
+       */
+      while (strcmp(window_bindings[which].name, 
+                    window_string_bindings[i].name) != 0)
+        which++;
+
+      /* Set the binding */
+      update_binding (&window_bindings[which],
+                      window_string_bindings[i].keybinding);
+
+      ++i;
+    }
+
+  i = 0;
+  which = 0;
+  while (screen_string_bindings[i].name)
+    {
+      /* Find which window_bindings entry this window_string_bindings entry
+       * corresponds to.
+       */
+      while (strcmp(screen_bindings[which].name, 
+                    screen_string_bindings[i].name) != 0)
+        which++;
+
+      /* Set the binding */
+      update_binding (&screen_bindings[which], 
+                      screen_string_bindings[i].keybinding);
+
+      ++i;
+    }
 #endif /* HAVE_GCONF */
 }
 
@@ -1605,10 +1687,21 @@
 
       ++i;
     }
+#else
+/* was:
+  int i;
+  for (i = 0; i < MAX_COMMANDS; i++)
+    commands[i] = NULL;
+*/
+  int i;
+  for (i = 0; i < MAX_REASONABLE_WORKSPACES; i++)
+    workspace_names[i] = g_strdup_printf (_("Workspace %d"), i + 1);
+
+  meta_topic (META_DEBUG_PREFS,
+              "Initialized workspace names\n");
 #endif /* HAVE_GCONF */
 }
 
-#ifdef HAVE_GCONF
 static gboolean
 update_binding (MetaKeyPref *binding,
                 const char  *value)
@@ -1656,6 +1749,7 @@
   return changed;
 }
 
+#ifdef HAVE_GCONF
 static const gchar*
 relative_key (const gchar* key)
 {
@@ -1953,6 +2047,9 @@
     }
   
   g_free (key);
+#else
+  g_free (workspace_names[i]);
+  workspace_names[i] = g_strdup (name);
 #endif /* HAVE_GCONF */
 }
 






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