summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-09-11 22:02:03 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-09-11 22:02:03 +0200
commit1d1c644027bb9263ed154a2aa257941624af4c38 (patch)
tree484a61b83926e6ecd12048a7fc094bebe8163071 /plugins
parentdfecc118a2268338a5699b9723812d606d648915 (diff)
osx: make hotkeys working
as a side effect, hotkeys plugin will now be built even if Xlib is not available, so localhotkeys will always work
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtkui/callbacks.c31
-rw-r--r--plugins/gtkui/hotkeys.c4
-rw-r--r--plugins/hotkeys/hotkeys.c77
3 files changed, 68 insertions, 44 deletions
diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c
index 55c3e598..507fab38 100644
--- a/plugins/gtkui/callbacks.c
+++ b/plugins/gtkui/callbacks.c
@@ -185,42 +185,22 @@ on_mainwin_key_press_event (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
-#ifndef __APPLE__
// local hotkeys
// first translate gdk modifiers into X11 constants
int mods = 0;
if (event->state & GDK_CONTROL_MASK) {
- mods |= ControlMask;
+ mods |= GDK_CONTROL_MASK;
}
if (event->state & GDK_MOD1_MASK) {
- mods |= Mod1Mask;
+ mods |= GDK_MOD1_MASK;
}
if (event->state & GDK_SHIFT_MASK) {
- mods |= ShiftMask;
+ mods |= GDK_SHIFT_MASK;
}
if (event->state & GDK_MOD4_MASK) {
- mods |= Mod4Mask;
+ mods |= GDK_MOD4_MASK;
}
- trace ("keycode: %x, mods %x\n", event->keyval, mods);
-
-#if 0
- // only execute actions if one of playlist widgets is in focus, or none
- GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (mainwin));
- if (focus) {
- GtkWidget *parent = gtk_widget_get_parent (focus);
- if (!parent) {
- return FALSE;
- }
- parent = gtk_widget_get_parent (parent);
- if (!parent) {
- return FALSE;
- }
- parent = gtk_widget_get_parent (parent);
- if (!parent || !DDB_IS_LISTVIEW (parent)) {
- return FALSE;
- }
- }
-#endif
+ trace ("pressed: keycode: %x, mods %x\n", event->keyval, mods);
DB_plugin_t *hkplug = deadbeef->plug_get_for_id ("hotkeys");
if (hkplug) {
@@ -233,7 +213,6 @@ on_mainwin_key_press_event (GtkWidget *widget,
}
}
trace ("action not found\n");
-#endif
return FALSE;
}
diff --git a/plugins/gtkui/hotkeys.c b/plugins/gtkui/hotkeys.c
index a34fb629..6e710f4a 100644
--- a/plugins/gtkui/hotkeys.c
+++ b/plugins/gtkui/hotkeys.c
@@ -609,11 +609,7 @@ typedef struct {
#define KEY(kname, kcode) { .name=kname, .keysym=kcode },
static const xkey_t keys[] = {
-#ifndef __APPLE__
#include "../hotkeys/keysyms.inc"
-#else
- { .name=NULL, .keysym=0 }
-#endif
};
static const char *
diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c
index 9450e36c..b77dcdc3 100644
--- a/plugins/hotkeys/hotkeys.c
+++ b/plugins/hotkeys/hotkeys.c
@@ -20,7 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifndef __APPLE__
#include <X11/Xlib.h>
+#endif
#include <ctype.h>
#ifdef __linux__
#include <sys/prctl.h>
@@ -36,17 +38,22 @@
static DB_hotkeys_plugin_t plugin;
DB_functions_t *deadbeef;
+
+#ifndef __APPLE__
static int finished;
static Display *disp;
static intptr_t loop_tid;
static int need_reset = 0;
+#endif
#define MAX_COMMAND_COUNT 256
typedef struct {
const char *name;
- KeySym keysym;
+ int keysym;
+#ifndef __APPLE__
int keycode; // after mapping
+#endif
} xkey_t;
#define KEY(kname, kcode) { .name=kname, .keysym=kcode},
@@ -67,12 +74,13 @@ typedef struct command_s {
static command_t commands [MAX_COMMAND_COUNT];
static int command_count = 0;
+#ifndef __APPLE__
static void
-init_mapped_keycodes (Display *disp, KeySym *syms, int first_kk, int last_kk, int ks_per_kk) {
+init_mapped_keycodes (Display *disp, int *syms, int first_kk, int last_kk, int ks_per_kk) {
int i, ks;
for (i = 0; i < last_kk-first_kk; i++)
{
- KeySym sym = * (syms + i*ks_per_kk);
+ int sym = * (syms + i*ks_per_kk);
for (ks = 0; keys[ks].name; ks++)
{
if (keys[ ks ].keysym == sym)
@@ -82,15 +90,17 @@ init_mapped_keycodes (Display *disp, KeySym *syms, int first_kk, int last_kk, in
}
}
}
+#endif
static int
-get_keycode (Display *disp, const char* name, KeySym *syms, int first_kk, int last_kk, int ks_per_kk) {
+get_keycode (const char* name, int *syms, int first_kk, int last_kk, int ks_per_kk) {
+#ifndef __APPLE__
trace ("get_keycode %s\n", name);
int i, ks;
for (i = 0; i < last_kk-first_kk; i++)
{
- KeySym sym = * (syms + i*ks_per_kk);
+ int sym = * (syms + i*ks_per_kk);
for (ks = 0; keys[ks].name; ks++)
{
if ( (keys[ ks ].keysym == sym) && (0 == strcmp (name, keys[ ks ].name)))
@@ -99,6 +109,14 @@ get_keycode (Display *disp, const char* name, KeySym *syms, int first_kk, int la
}
}
}
+#else
+ for (int i = 0; keys[i].name; i++) {
+ if (!strcmp (name, keys[i].name)) {
+ trace ("init: key %s code %x\n", name, keys[i].keysym);
+ return keys[i].keysym;
+ }
+ }
+#endif
return 0;
}
@@ -225,16 +243,30 @@ find_action_by_name (const char *command, int *is_14_action) {
return actions;
}
+#ifndef __APPLE__
static int
-read_config (Display *disp)
-{
+read_config (Display *disp) {
int ks_per_kk;
int first_kk, last_kk;
- KeySym* syms;
+ int* syms;
XDisplayKeycodes (disp, &first_kk, &last_kk);
syms = XGetKeyboardMapping (disp, first_kk, last_kk - first_kk, &ks_per_kk);
-
+#else
+#define ShiftMask (1<<0)
+#define LockMask (1<<1)
+#define ControlMask (1<<2)
+#define Mod1Mask (1<<3)
+#define Mod2Mask (1<<4)
+#define Mod3Mask (1<<5)
+#define Mod4Mask (1<<6)
+#define Mod5Mask (1<<7)
+ int ks_per_kk = -1;
+ int first_kk = -1, last_kk = -1;
+ int* syms = NULL;
+static int
+read_config (void) {
+#endif
DB_conf_item_t *item = deadbeef->conf_find ("hotkey.", NULL);
while (item) {
if (command_count == MAX_COMMAND_COUNT)
@@ -259,7 +291,7 @@ read_config (Display *disp)
}
cmd_entry->ctx = atoi (token);
if (cmd_entry->ctx < 0 || cmd_entry->ctx >= DDB_ACTION_CTX_COUNT) {
- trace ("hotkeys: invalid ctx %d\n");
+ trace ("hotkeys: invalid ctx %d\n", cmd_entry->ctx);
goto out;
}
if ((script = gettoken (script, token)) == 0) {
@@ -314,7 +346,7 @@ read_config (Display *disp)
}
else {
// lookup name table
- cmd_entry->keycode = get_keycode (disp, p, syms, first_kk, last_kk, ks_per_kk);
+ cmd_entry->keycode = get_keycode (p, syms, first_kk, last_kk, ks_per_kk);
}
if (!cmd_entry->keycode)
{
@@ -335,6 +367,7 @@ read_config (Display *disp)
out:
item = deadbeef->conf_find ("hotkey.", item);
}
+#ifndef __APPLE__
XFree (syms);
int i;
// need to grab it here to prevent gdk_x_error from being called while we're
@@ -361,6 +394,7 @@ out:
XGrabKey (disp, commands[i].keycode, commands[i].modifier | flags, DefaultRootWindow (disp), False, GrabModeAsync, GrabModeAsync);
}
}
+#endif
return 0;
}
@@ -374,9 +408,12 @@ hotkeys_load (DB_functions_t *api) {
static void
cleanup () {
command_count = 0;
+#ifndef __APPLE__
XCloseDisplay (disp);
+#endif
}
+#ifndef __APPLE__
static int
x_err_handler (Display *d, XErrorEvent *evt) {
#if 0
@@ -452,9 +489,11 @@ hotkeys_event_loop (void *unused) {
usleep (200 * 1000);
}
}
+#endif
static int
hotkeys_connect (void) {
+#ifndef __APPLE__
finished = 0;
loop_tid = 0;
disp = XOpenDisplay (NULL);
@@ -469,24 +508,28 @@ hotkeys_connect (void) {
int ks_per_kk;
int first_kk, last_kk;
- KeySym* syms;
+ int* syms;
XDisplayKeycodes (disp, &first_kk, &last_kk);
syms = XGetKeyboardMapping (disp, first_kk, last_kk - first_kk, &ks_per_kk);
init_mapped_keycodes (disp, syms, first_kk, last_kk, ks_per_kk);
XFree (syms);
XSync (disp, 0);
loop_tid = deadbeef->thread_start (hotkeys_event_loop, 0);
+#else
+ read_config ();
+#endif
return 0;
}
static int
hotkeys_disconnect (void) {
+#ifndef __APPLE__
if (loop_tid) {
finished = 1;
deadbeef->thread_join (loop_tid);
- cleanup ();
}
-
+#endif
+ cleanup ();
return 0;
}
@@ -510,6 +553,7 @@ hotkeys_get_action_for_keycombo (int key, int mods, int isglobal, int *ctx) {
key = tolower (key);
}
+#ifndef __APPLE__
int keycode = 0;
for (i = 0; keys[i].name; i++) {
if (key == keys[i].keysym) {
@@ -521,6 +565,9 @@ hotkeys_get_action_for_keycombo (int key, int mods, int isglobal, int *ctx) {
trace ("hotkeys: unknown keysym 0x%X\n", key);
return NULL;
}
+#else
+ int keycode = key;
+#endif
trace ("hotkeys: keysym 0x%X mapped to 0x%X\n", key, keycode);
@@ -537,8 +584,10 @@ hotkeys_get_action_for_keycombo (int key, int mods, int isglobal, int *ctx) {
void
hotkeys_reset (void) {
+#ifndef __APPLE__
need_reset = 1;
trace ("hotkeys: reset flagged\n");
+#endif
}
int