After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 114796 - binding to arbitrary shell commands
binding to arbitrary shell commands
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: [obsolete] Keybinding
git master
Other Linux
: Normal enhancement
: ---
Assigned To: Control-Center Maintainers
Control-Center Maintainers
: 115483 162233 170856 321913 327110 345885 373926 395754 562648 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-06-09 19:24 UTC by Luke
Modified: 2008-12-03 18:08 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Draft implementation of biding any key to shell command. (12.14 KB, patch)
2004-10-13 21:52 UTC, Michal Moskal
none Details | Review
work in progress (23.94 KB, patch)
2005-08-05 20:55 UTC, Xavier Claessens
none Details | Review
it works better... (29.37 KB, patch)
2005-08-06 08:19 UTC, Xavier Claessens
none Details | Review
It works now !! (29.47 KB, patch)
2005-08-06 10:55 UTC, Xavier Claessens
none Details | Review
yet another bugfix (29.46 KB, patch)
2005-08-06 16:39 UTC, Xavier Claessens
none Details | Review
patch v0.1 (42.00 KB, patch)
2005-08-11 20:47 UTC, Xavier Claessens
none Details | Review
v0.1 (10.34 KB, text/x-csrc)
2005-08-11 20:48 UTC, Xavier Claessens
  Details
header v0.1 (1.94 KB, text/x-chdr)
2005-08-11 20:49 UTC, Xavier Claessens
  Details
patch v0.2 (41.92 KB, patch)
2005-08-13 19:28 UTC, Xavier Claessens
none Details | Review
custom-binding.c v0.2 (9.96 KB, text/plain)
2005-08-13 19:29 UTC, Xavier Claessens
  Details
custom-binding.h (1.94 KB, text/plain)
2005-08-13 19:29 UTC, Xavier Claessens
  Details
screenshot (161.97 KB, image/png)
2005-08-14 16:55 UTC, Xavier Claessens
  Details
Same patch against HEAD (39.74 KB, patch)
2006-01-03 20:45 UTC, Xavier Claessens
none Details | Review
adding a custom shortcut (91.62 KB, image/png)
2008-10-24 02:38 UTC, Matthias Clasen
  Details
editing a custom shortcut (107.91 KB, image/png)
2008-10-24 02:38 UTC, Matthias Clasen
  Details
patch (30.13 KB, patch)
2008-10-24 02:39 UTC, Matthias Clasen
needs-work Details | Review
cleaned up patch (30.82 KB, patch)
2008-10-26 05:34 UTC, Matthias Clasen
needs-work Details | Review
next version (31.76 KB, patch)
2008-10-26 18:26 UTC, Matthias Clasen
committed Details | Review

Description Luke 2003-06-09 19:24:25 UTC
I'd like to be able to bind keys to arbitrary shell commands
Comment 1 Rob Adams 2003-06-19 14:45:40 UTC
*** Bug 115483 has been marked as a duplicate of this bug. ***
Comment 2 Daniel Silverstone 2003-06-19 14:51:43 UTC
From my bug against metacity,

You can do it manually by editing the
apps/metacity/keybinding_commands and apps/metacity/global_keybindings
gconf keys using gconf-editor.

This seems fundamentally flawed since I thought GNOME was meant to be
WM independant. Surely generic keybindings like this should be stored
in a non WM-specific part of the gconf tree?
Comment 3 Daniel Silverstone 2003-07-09 12:59:00 UTC
Anyone going to do anything about this? it is an apalling omission
which seriously limits functionality and usability
Comment 4 Sergej Kotliar 2004-04-13 10:53:59 UTC
This needs to be done, either with the current Metacity Gconf bindings or with
the Keybinding tool.

Would it be so hard to just add a few more lines to be edited in
gnome-keybinding-properties
Comment 5 Michal Moskal 2004-10-13 21:52:51 UTC
Created attachment 32586 [details] [review]
Draft implementation of biding any key to shell command.

I also missed this functionality, so I implemented it. It's probably far from
perfect -- you need to set the command with gconf and there is limit of 10
shell commands, but it is better then nothing (and in fact all I need).

Maybe the key configuration should be hidden from gnome-keybinding-properties
if you cannot set commands?

Any chances it is going to be included mainstream?
Comment 6 Michal Moskal 2004-10-13 22:00:50 UTC
I forgot -- the patch implements this in multimedia-keys part, so unlike in
metacity the special multimedia keys (seen any new keyboard without them?:-)
work OK. And of course it is WM-independant.
Comment 7 Sebastien Bacher 2004-12-27 11:17:52 UTC
*** Bug 162233 has been marked as a duplicate of this bug. ***
Comment 8 Teppo Turtiainen 2005-07-15 10:14:08 UTC
*** Bug 170856 has been marked as a duplicate of this bug. ***
Comment 9 Xavier Claessens 2005-08-05 20:55:08 UTC
Created attachment 50294 [details] [review]
work in progress

I'm working on a better patch. This patch doesn't work well, but I post it to
have  feedback.

That's my first gtk code, and I don't understand gtk_tree_view very well. So I
don't understand why my patch doesn't work :-(
Comment 10 Xavier Claessens 2005-08-06 08:19:49 UTC
Created attachment 50309 [details] [review]
it works better...

it works far better now. The only problem a have is when I edit a command, text
redered isn't updated (but gconf key is)... close window and open again and the
new command is displayed... don't understand why... but i'm not a tree_view
expert at all !

Any comment ?
Comment 11 Xavier Claessens 2005-08-06 08:21:42 UTC
version=head and priority=high (because of the patch)
Comment 12 Xavier Claessens 2005-08-06 10:55:20 UTC
Created attachment 50312 [details] [review]
It works now !!

this is the same patch, but with 3lines more to fix the bug I had.

Any comment ?
Comment 13 Xavier Claessens 2005-08-06 16:39:10 UTC
Created attachment 50322 [details] [review]
yet another bugfix

Sorry, stupid error in preview patch. Now it is better :)
Comment 14 Nigel Tao 2005-08-07 00:55:45 UTC
For the record, there was a discussion on desktop-devel-list around June/July
2005, with pointers to another patch.

http://mail.gnome.org/archives/desktop-devel-list/2005-June/msg00179.html

http://mail.gnome.org/archives/desktop-devel-list/2005-July/msg00007.html
Comment 15 Xavier Claessens 2005-08-11 20:47:19 UTC
Created attachment 50590 [details] [review]
patch v0.1

this is a rework of patch proposed on mailing list. I keep the same UI, but
move gconf keys to /apps/gnome_settings_daemon/custom_keybindings and adapt
gnome-settings-multimedia-keys to read those keys and run commands.

So it is WM independant.

This patch needs 2 new files to be inclued in
gnome-control-center/capplets/keybindings
Comment 16 Xavier Claessens 2005-08-11 20:48:33 UTC
Created attachment 50591 [details]
v0.1
Comment 17 Xavier Claessens 2005-08-11 20:49:05 UTC
Created attachment 50592 [details]
header v0.1
Comment 18 Xavier Claessens 2005-08-13 19:28:42 UTC
Created attachment 50658 [details] [review]
patch v0.2

bugfix. When adding a new custom binding tree-view shoud select the new row,
but I don't know how to make that.
Comment 19 Xavier Claessens 2005-08-13 19:29:22 UTC
Created attachment 50659 [details]
custom-binding.c v0.2
Comment 20 Xavier Claessens 2005-08-13 19:29:49 UTC
Created attachment 50660 [details]
custom-binding.h
Comment 21 Vincent Untz 2005-08-14 15:49:53 UTC
Sébastien: what do you think of this?

Xavier: it will have to wait after the 2.12 release since we're UI-frozen...
Comment 22 Sebastien Bacher 2005-08-14 16:21:00 UTC
I've not played with that yet since that's GNOME  material. A screenshoot and
some explanation on how it works would be welcome for people who want to comment
without patching/building the code. I'll put a new comment when playing with the
that.
Comment 23 Xavier Claessens 2005-08-14 16:55:08 UTC
Created attachment 50687 [details]
screenshot

As you can see, it add a pair of key for each custom binding. The multimedia
daemon has a list of all custom actions and when key is pressed it check if it
is binded to a custom action, if so it exectute the corresponding command.
Comment 24 Teppo Turtiainen 2005-11-27 09:32:30 UTC
*** Bug 321913 has been marked as a duplicate of this bug. ***
Comment 25 Xavier Claessens 2006-01-03 20:45:29 UTC
Created attachment 56732 [details] [review]
Same patch against HEAD

I ported the patch to actual HEAD.
Comment 26 Rodrigo Moya 2006-01-11 10:39:25 UTC
I see a few problems with how it works:

* the dialog looks bad, since there is very little space when opened on 1024x768 for the treeview, due to the new buttons
* not sure if it's me, but the rows in the treeview are invisible, until you pass the mouse over them ??? Then, they become invisible again when the mouse moves to another row.
* it doesn't work for me, might be that I chose bad keybinding
Comment 27 Glynn Foster 2006-01-17 02:49:03 UTC
I think any patch that goes in now should have #108689 in mind, since that's an often asked feature within our internal mailing lists.
Comment 28 Jens Granseuer 2007-01-12 21:38:05 UTC
*** Bug 395754 has been marked as a duplicate of this bug. ***
Comment 29 Jens Granseuer 2007-01-15 19:06:03 UTC
*** Bug 327110 has been marked as a duplicate of this bug. ***
Comment 30 Jens Granseuer 2007-01-30 21:34:58 UTC
*** Bug 373926 has been marked as a duplicate of this bug. ***
Comment 31 Thomas Wood 2007-02-10 18:18:57 UTC
*** Bug 373939 has been marked as a duplicate of this bug. ***
Comment 32 Thomas Wood 2007-02-10 18:29:45 UTC
*** Bug 362578 has been marked as a duplicate of this bug. ***
Comment 33 Jens Granseuer 2007-03-03 13:59:53 UTC
*** Bug 345885 has been marked as a duplicate of this bug. ***
Comment 34 Bastien Nocera 2007-05-31 13:56:41 UTC
FYI, and until the patch is cleaned up/merged, here's some docs:
http://live.gnome.org/ControlCenter/CustomKeybindings
Comment 35 Sébastien Bertrand 2007-05-31 17:16:01 UTC
Great !

Now, if we are able to bind mouse buttons, there will be no more need of xbindkeys to do that job...

See : http://bugzilla.gnome.org/show_bug.cgi?id=140279

What could be great too would be to be able to bind to command together. For example I have the following lines in my xbindkeyrc file :

"xvkbd -xsendevent -text "\[Alt_L]\[Left]""
   b:8

This lines bind the button 8 of my mouse to <Alt_L> + <Left>... In that case xvkbd do the job, but maybe there is a more elegant way to do that ?
Comment 36 Jens Granseuer 2008-04-06 11:46:12 UTC
For future reference, I'd like to see a UI for this that doesn't pop up a separate dialog window for adding/editing custom shortcuts but instead uses editable entries in the tree view to achieve this. As Reodrigo mentioned, the proposed UI wastes a lot of space for something that's probably not essential for most. One might also experiment a bit with using right-click context menus instead of buttons for some of the actions.
Comment 37 Matthias Clasen 2008-10-24 02:37:00 UTC
Cell editors do a really poor job for this, so I went ahead and wrote a patch that uses a popup anyway. One reason why a cell editor is now the right solution here is that you really want to have a separate label/name for the action to display in the list, not just the command, which can look ugly/long/complicated/intimidating. 

With my patch, editing an existing custom shortcut works by clicking on its name, so there is no need for an edit button, at least. Of course, the remove button only lets you remove custom shortcuts, not others.

The patch also supports lockdown of custom shortcuts via the accepted_keys gconf key (there's a patch for that in another bug). When accepted_keys is set, the add button is disabled.
Comment 38 Matthias Clasen 2008-10-24 02:38:10 UTC
Created attachment 121234 [details]
adding a custom shortcut
Comment 39 Matthias Clasen 2008-10-24 02:38:47 UTC
Created attachment 121235 [details]
editing a custom shortcut
Comment 40 Matthias Clasen 2008-10-24 02:39:55 UTC
Created attachment 121236 [details] [review]
patch
Comment 41 Jens Granseuer 2008-10-25 11:42:04 UTC
+      if (g_file_test ("./gnome-keybinding-properties.glade", G_FILE_TEST_EXISTS))
+        dialog = glade_xml_new ("./gnome-keybinding-properties.glade", NULL, NULL);
+      else  
+        dialog = glade_xml_new (GNOMECC_GLADE_DIR "/gnome-keybinding-properties.glade", NULL, NULL);

Please don't do that.

I also don't particularly like keeping the entire GladeXML around you for the edit window. How about just storing the GtkWindow in a static?

+      if (keys_list[j].cmd_name != NULL)
+        {
+          command = gconf_client_get_string (client, keys_list[j].cmd_name, NULL);
+	}
+      else
+        {
+	  command = NULL;
+	}

Indentation.

+    g_print ("not a custom shortcut\n");

Please remove (or use g_debug if you must).

+  gtk_tree_store_remove (GTK_TREE_STORE (model), iter); if (!gtk_tree_model_iter_has_child (model, &parent))

Missed a NL there.

+static gchar *
+find_free_gconf_key (void)

Please provide for failure here. 1000 *should* be big enough, but better safe than sorry.

+          gtk_tree_view_set_cursor (treeview, path,
+			            gtk_tree_view_get_column (treeview, 0),
+			            FALSE);
+	  update_custom_shortcut (model, &iter);

Indentation.

+	{
+          gtk_widget_grab_focus (GTK_WIDGET (treeview));
+          gtk_tree_view_set_cursor (treeview,
 			    path,
 			    gtk_tree_view_get_column (treeview, 1),
 			    TRUE);
+        }

Same.

+          gtk_tree_view_set_cursor (tree_view, path,
+			            gtk_tree_view_get_column (tree_view, 0),
+			            FALSE);
+	  update_custom_shortcut (model, &iter);

Same.

+  	GladeXML *dialog = data;
+        GtkTreeView *treeview;

Same.

+	else if (response_id == 0)
+          {
+	    add_custom_shortcut (treeview, model);
+	  }
+	else if (response_id == 1)
+          {
+	    selection = gtk_tree_view_get_selection (treeview);
+            if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+	      {
+                remove_custom_shortcut (model, &iter);
+              }
+	  }

Use (predefined?) symbolic ids instead.
Indentation.

+  accepted_keys = gconf_client_get_list (client, 
+                                         GCONF_BINDING_DIR "/accepted_keys", 
+					 GCONF_VALUE_STRING,
+					 NULL);

Indentation.

+      gtk_widget_set_sensitive (WID("add-button"), FALSE);

Please use "WID (...)". Several other occurences.

+	    <widget class="GtkButton" id="okbutton1">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-ok</property>

gtk-apply?

+		  <property name="text" translatable="yes"></property>

Not translatable. Twice.

Still not completely sure about the lock-down stuff. Need to find some time to think it over.
Comment 42 Matthias Clasen 2008-10-25 20:14:57 UTC
Sorry, I forgot to mention that the patch was not polished or ready for committing. I was just interested in your opinion on the idea in general 
Comment 43 Matthias Clasen 2008-10-26 05:34:02 UTC
Created attachment 121371 [details] [review]
cleaned up patch
Comment 44 Jens Granseuer 2008-10-26 09:31:27 UTC
Considering the label you added, yes, the general approach looks valid to me. I suppose you noticed. ;-)

+static gchar *
+find_free_gconf_key (void)
+{
...
+}

This funtion (and the calling one) should take into account that it might not find a free slot. Unlikely, but I'm sure somebody will try it.

+		  <property name="text" translatable="yes"></property>

Not translatable.

+		  <property name="text" translatable="yes"></property>

There was a batch of patches once upon a time to remove these hardcoded settings from glade files. Let's not add them back now.

Comment 45 Matthias Clasen 2008-10-26 18:26:39 UTC
Created attachment 121389 [details] [review]
next version

I've removed the empty strings and added an error dialog for 'too many custom shortcuts'. I've also improved the formatting of the error dialog somewhat.
Comment 46 Jens Granseuer 2008-10-26 18:33:32 UTC
+  return glade_xml_new (/*GNOMECC_GLADE_DIR*/ "./gnome-keybinding-properties.glade",
+                        NULL, NULL);

Don't forget to fix this.
Comment 47 Matthias Clasen 2008-10-26 18:35:22 UTC
grr, yeah. I'll remove that
Comment 48 Matthias Clasen 2008-10-26 18:42:33 UTC
I've also remove the accepted_keys lockdown stuff, going to file a separate bug about that.

2008-10-26  Matthias Clasen  <mclasen@redhat.com>

        Bug 114796 – binding to arbitrary shell commands

        * gnome-keybinding-properties.c:
        * gnome-keybinding-properties.glade: Add UI for adding and
        removing named custom shortcuts.
Comment 49 Jens Granseuer 2008-12-03 18:08:00 UTC
*** Bug 562648 has been marked as a duplicate of this bug. ***