summaryrefslogtreecommitdiff
path: root/plugins/hotkeys
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/hotkeys')
-rw-r--r--plugins/hotkeys/hotkeys.c82
-rw-r--r--plugins/hotkeys/hotkeys.h30
-rw-r--r--plugins/hotkeys/keysyms.inc2
3 files changed, 89 insertions, 25 deletions
diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c
index 622fc5fb..959dbd30 100644
--- a/plugins/hotkeys/hotkeys.c
+++ b/plugins/hotkeys/hotkeys.c
@@ -22,13 +22,15 @@
#include <X11/Xlib.h>
#include <ctype.h>
+#include "hotkeys.h"
#include "../../deadbeef.h"
-static DB_misc_t plugin;
+static DB_hotkeys_plugin_t plugin;
static DB_functions_t *deadbeef;
static int finished;
static Display *disp;
static intptr_t loop_tid;
+static int need_reset = 0;
#define MAX_COMMAND_COUNT 256
@@ -67,7 +69,7 @@ get_keycode (Display *disp, const char* name, KeySym *syms, int first_kk, int la
for (i = 0; i < last_kk-first_kk; i++)
{
KeySym sym = * (syms + i*ks_per_kk);
- for (ks = 0; ks < sizeof (keys) / sizeof (xkey_t); ks++)
+ for (ks = 0; keys[ks].name; ks++)
{
if ( (keys[ ks ].keysym == sym) && (0 == strcmp (name, keys[ ks ].name)))
{
@@ -257,6 +259,12 @@ read_config (Display *disp)
item = deadbeef->conf_find ("hotkeys.", item);
}
XFree (syms);
+ int i;
+ // need to grab it here to prevent gdk_x_error from being called while we're
+ // doing it on other thread
+ for (i = 0; i < command_count; i++) {
+ XGrabKey (disp, commands[i].keycode, commands[i].modifier, DefaultRootWindow (disp), False, GrabModeAsync, GrabModeAsync);
+ }
}
DB_plugin_t *
@@ -271,11 +279,29 @@ cleanup () {
XCloseDisplay (disp);
}
+static int
+x_err_handler (Display *d, XErrorEvent *evt) {
+ char buffer[1024];
+ XGetErrorText (d, evt->error_code, buffer, sizeof (buffer));
+ fprintf (stderr, "hotkeys: xlib error: %s\n", buffer);
+}
+
static void
hotkeys_event_loop (void *unused) {
int i;
while (!finished) {
+ if (need_reset) {
+ XSetErrorHandler (x_err_handler);
+ for (int i = 0; i < command_count; i++) {
+ XUngrabKey (disp, commands[i].keycode, commands[i].modifier, DefaultRootWindow (disp));
+ }
+ memset (commands, 0, sizeof (commands));
+ command_count = 0;
+ read_config (disp);
+ need_reset = 0;
+ }
+
XEvent event;
while (XPending (disp))
{
@@ -297,13 +323,6 @@ hotkeys_event_loop (void *unused) {
}
static int
-x_err_handler (Display *d, XErrorEvent *evt) {
- char buffer[1024];
- XGetErrorText (d, evt->error_code, buffer, sizeof (buffer));
- fprintf (stderr, "hotkeys: xlib error: %s\n", buffer);
-}
-
-static int
hotkeys_start (void) {
finished = 0;
loop_tid = 0;
@@ -316,12 +335,6 @@ hotkeys_start (void) {
XSetErrorHandler (x_err_handler);
read_config (disp);
- int i;
- // need to grab it here to prevent gdk_x_error from being called while we're
- // doing it on other thread
- for (i = 0; i < command_count; i++) {
- XGrabKey (disp, commands[i].keycode, commands[i].modifier, DefaultRootWindow (disp), False, GrabModeAsync, GrabModeAsync);
- }
XSync (disp, 0);
if (command_count > 0) {
loop_tid = deadbeef->thread_start (hotkeys_event_loop, 0);
@@ -340,16 +353,35 @@ hotkeys_stop (void) {
}
}
+const char *
+hotkeys_get_name_for_keycode (int keycode) {
+ for (int i = 0; keys[i].name; i++) {
+ if (keycode == keys[i].keysym) {
+ return keys[i].name;
+ }
+ }
+ return NULL;
+}
+
+void
+hotkeys_reset (void) {
+ need_reset = 1;
+}
+
// define plugin interface
-static DB_misc_t plugin = {
- DB_PLUGIN_SET_API_VERSION
- .plugin.type = DB_PLUGIN_MISC,
- .plugin.name = "Global hotkeys support",
- .plugin.descr = "Allows to control player with global hotkeys",
- .plugin.author = "Viktor Semykin",
- .plugin.email = "thesame.ml@gmail.com",
- .plugin.website = "http://deadbeef.sf.net",
- .plugin.start = hotkeys_start,
- .plugin.stop = hotkeys_stop
+static DB_hotkeys_plugin_t plugin = {
+ .misc.plugin.api_vmajor = DB_API_VERSION_MAJOR,
+ .misc.plugin.api_vminor = DB_API_VERSION_MINOR,
+ .misc.plugin.type = DB_PLUGIN_MISC,
+ .misc.plugin.id = "hotkeys",
+ .misc.plugin.name = "Global hotkeys support",
+ .misc.plugin.descr = "Allows to control player with global hotkeys",
+ .misc.plugin.author = "Viktor Semykin",
+ .misc.plugin.email = "thesame.ml@gmail.com",
+ .misc.plugin.website = "http://deadbeef.sf.net",
+ .misc.plugin.start = hotkeys_start,
+ .misc.plugin.stop = hotkeys_stop,
+ .get_name_for_keycode = hotkeys_get_name_for_keycode,
+ .reset = hotkeys_reset,
};
diff --git a/plugins/hotkeys/hotkeys.h b/plugins/hotkeys/hotkeys.h
new file mode 100644
index 00000000..f520aa41
--- /dev/null
+++ b/plugins/hotkeys/hotkeys.h
@@ -0,0 +1,30 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifndef __HOTKEYS_H
+#define __HOTKEYS_H
+
+#include "../../deadbeef.h"
+
+typedef struct DB_hotkeys_plugin_s {
+ DB_misc_t misc;
+ const char *(*get_name_for_keycode) (int keycode);
+ void (*reset) (void);
+} DB_hotkeys_plugin_t;
+
+#endif
diff --git a/plugins/hotkeys/keysyms.inc b/plugins/hotkeys/keysyms.inc
index af164fef..1f66304b 100644
--- a/plugins/hotkeys/keysyms.inc
+++ b/plugins/hotkeys/keysyms.inc
@@ -2189,3 +2189,5 @@ KEY("XF86Ungrab", 0x1008FE20)
KEY("XF86ClearGrab", 0x1008FE21)
KEY("XF86Next_VMode", 0x1008FE22)
KEY("XF86Prev_VMode", 0x1008FE23)
+
+KEY(NULL, 0)