Skip to content

Commit 50ba2ca

Browse files
committed
GTK global hotkeys for Windows
1 parent 78dae36 commit 50ba2ca

File tree

14 files changed

+970
-214
lines changed

14 files changed

+970
-214
lines changed

src/hotkey/api_hotkey.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
/*
2+
* api_hotkey.h
3+
* Audacious
4+
*
5+
* Copyright (C) 2005-2020 Audacious team
6+
*
7+
* XMMS - Cross-platform multimedia player
8+
* Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
9+
* Thomas Nilsson and 4Front Technologies
10+
* Copyright (C) 1999-2003 Haavard Kvaalen
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; under version 3 of the License.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses>.
23+
*
24+
* The Audacious team does not consider modular code linking to
25+
* Audacious or using our public API to be a derived work.
26+
*/
27+
128
#ifndef _X_HOTKEY_H_INCLUDED
229
#define _X_HOTKEY_H_INCLUDED
330

@@ -32,6 +59,7 @@ class Hotkey
3259
static void add_hotkey(HotkeyConfiguration ** pphotkey, OS_KeySym keysym,
3360
int mask, int type, EVENT event);
3461
static void key_to_string(int key, char ** out_keytext);
62+
static char* create_human_readable_keytext(const char* const keytext, int key, int mask);
3563
};
3664

3765
#ifndef _WIN32

src/hotkey/grab.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
/*
2+
* grab.h
3+
* Audacious
4+
*
5+
* Copyright (C) 2005-2020 Audacious team
6+
*
7+
* XMMS - Cross-platform multimedia player
8+
* Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
9+
* Thomas Nilsson and 4Front Technologies
10+
* Copyright (C) 1999-2003 Haavard Kvaalen
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; under version 3 of the License.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses>.
23+
*
24+
* The Audacious team does not consider modular code linking to
25+
* Audacious or using our public API to be a derived work.
26+
*/
27+
128
#ifndef _GRAB_H_INCLUDED_
229
#define _GRAB_H_INCLUDED_
330

src/hotkey/gui.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This file is part of audacious-hotkey plugin for audacious
33
*
44
* Copyright (c) 2007 - 2008 Sascha Hlusiak <[email protected]>
5-
* Name: gui.c
6-
* Description: gui.c
5+
* Name: gui.cc
6+
* Description: gui.cc
77
*
88
* Part of this code is from itouch-ctrl plugin.
99
* Authors of itouch-ctrl are listed below:
@@ -90,7 +90,6 @@ static const char * event_desc[EVENT_MAX] = {
9090
static gboolean on_entry_key_press_event(GtkWidget * widget,
9191
GdkEventKey * event, void * user_data)
9292
{
93-
AUDDBG("lHotkeyFlow:Entry");
9493
KeyControls * controls = (KeyControls *)user_data;
9594

9695
if (event->keyval == GDK_Tab)
@@ -99,6 +98,10 @@ static gboolean on_entry_key_press_event(GtkWidget * widget,
9998
return false;
10099
if (event->keyval == GDK_Return && ((event->state & ~GDK_LOCK_MASK) == 0))
101100
return false;
101+
#ifdef _WIN32
102+
if (event->keyval == GDK_Meta_L || event->keyval == GDK_Meta_R)
103+
return false;
104+
#endif
102105
if (event->keyval == GDK_ISO_Left_Tab)
103106
{
104107
Hotkey::set_keytext(controls->keytext, controls->hotkey.key,
@@ -126,7 +129,7 @@ static gboolean on_entry_key_press_event(GtkWidget * widget,
126129

127130
Hotkey::set_keytext(controls->keytext, is_mod ? 0 : event->hardware_keycode,
128131
mod, TYPE_KEY);
129-
AUDDBG("lHotkeyFlow:Leave");
132+
// Returning TRUE indicates that the event has been handled, and that it should not propagate further.
130133
return true;
131134
}
132135

@@ -299,11 +302,7 @@ void * make_config_widget()
299302
load_config();
300303

301304
plugin_cfg = get_config();
302-
303-
// NOTE d: implement in WIN
304-
#ifndef _WIN32
305305
ungrab_keys();
306-
#endif
307306

308307
main_vbox = gtk_vbox_new(false, 4);
309308

@@ -503,12 +502,7 @@ void add_callback(GtkWidget * widget, void * data)
503502
void destroy_callback()
504503
{
505504
KeyControls * controls = first_controls;
506-
507-
// NOTE d: implement in WIN
508-
#ifndef _WIN32
509505
grab_keys();
510-
#endif
511-
512506
while (controls)
513507
{
514508
KeyControls * old;

src/hotkey/gui.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
/*
2+
* gui.h
3+
* Audacious
4+
*
5+
* Copyright (C) 2005-2020 Audacious team
6+
*
7+
* XMMS - Cross-platform multimedia player
8+
* Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
9+
* Thomas Nilsson and 4Front Technologies
10+
* Copyright (C) 1999-2003 Haavard Kvaalen
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; under version 3 of the License.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses>.
23+
*
24+
* The Audacious team does not consider modular code linking to
25+
* Audacious or using our public API to be a derived work.
26+
*/
27+
128
#ifndef _GUI_H_INCLUDED_
229
#define _GUI_H_INCLUDED_
330

src/hotkey/hotkey_api_common.cc

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
1+
/*
2+
* hotkey_api_common.cc
3+
* Audacious
4+
*
5+
* Copyright (C) 2005-2020 Audacious team
6+
*
7+
* XMMS - Cross-platform multimedia player
8+
* Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
9+
* Thomas Nilsson and 4Front Technologies
10+
* Copyright (C) 1999-2003 Haavard Kvaalen
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; under version 3 of the License.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses>.
23+
*
24+
* The Audacious team does not consider modular code linking to
25+
* Audacious or using our public API to be a derived work.
26+
*/
227

328
#include "api_hotkey.h"
429
#include <X11/X.h>
@@ -38,10 +63,6 @@ template int Hotkey::calculate_mod<GdkEventButton>(GdkEventButton * event);
3863

3964
std::pair<int, int> Hotkey::get_is_mod(GdkEventKey * event)
4065
{
41-
#ifdef _WIN32
42-
AUDDBG("lHotkeyFlow:Win call: get_is_mod.%s",
43-
gdk_keyval_name(event->keyval));
44-
#endif
4566
int mod = 0;
4667
int is_mod = 0;
4768

@@ -83,14 +104,7 @@ void Hotkey::set_keytext(GtkWidget * entry, int key, int mask, int type)
83104
}
84105
else
85106
{
86-
static const char * modifier_string[] = {
87-
"Control", "Shift", "Alt", "Mod2", "Mod3", "Super", "Mod5"};
88-
static const unsigned int modifiers[] = {
89-
HK_CONTROL_MASK, HK_SHIFT_MASK, HK_MOD1_ALT_MASK, HK_MOD2_MASK,
90-
HK_MOD3_MASK, HK_MOD4_MASK, HK_MOD5_MASK};
91-
const char * strings[9];
92107
char * keytext = nullptr;
93-
int i, j;
94108
if (type == TYPE_KEY)
95109
{
96110
Hotkey::key_to_string(key, &keytext);
@@ -99,17 +113,7 @@ void Hotkey::set_keytext(GtkWidget * entry, int key, int mask, int type)
99113
{
100114
keytext = g_strdup_printf("Button%d", key);
101115
}
102-
103-
for (i = 0, j = 0; j < 7; j++)
104-
{
105-
if (mask & modifiers[j])
106-
strings[i++] = modifier_string[j];
107-
}
108-
if (key != 0)
109-
strings[i++] = keytext;
110-
strings[i] = nullptr;
111-
112-
text = g_strjoinv(" + ", (char **)strings);
116+
text = Hotkey::create_human_readable_keytext(keytext, key, mask);
113117
g_free(keytext);
114118
}
115119

src/hotkey/plugin.cc

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This file is part of audacious-hotkey plugin for audacious
33
*
44
* Copyright (c) 2007 - 2008 Sascha Hlusiak <[email protected]>
5-
* Name: plugin.c
6-
* Description: plugin.c
5+
* Name: plugin.cc
6+
* Description: plugin.cc
77
*
88
* Part of this code is from itouch-ctrl plugin.
99
* Authors of itouch-ctrl are listed below:
@@ -46,12 +46,13 @@
4646
#include "api_hotkey.h"
4747
#include "grab.h"
4848
#include "gui.h"
49-
#include "plugin.h"
5049

5150
#ifdef BUILT_FROM_CMAKE
5251
#include "../../audacious-plugins_simpleAF/src/thirdparty/d_custom_logger.hpp"
5352
#endif
5453

54+
extern bool system_up_and_running;
55+
5556
class GlobalHotkeys : public GeneralPlugin
5657
{
5758
public:
@@ -66,28 +67,24 @@ class GlobalHotkeys : public GeneralPlugin
6667
void cleanup() override;
6768
};
6869

69-
EXPORT GlobalHotkeys aud_plugin_instance;
70-
71-
#ifndef _WIN32
7270
/* global vars */
73-
static
74-
#else
75-
PluginConfig plugin_cfg;
76-
#endif
77-
78-
const char GlobalHotkeys::about[] = N_(
79-
"Global Hotkey Plugin\n"
80-
"Control the player with global key combinations or multimedia "
81-
"keys.\n\n"
82-
"Copyright (C) 2007-2008 Sascha Hlusiak <[email protected]>\n\n"
83-
"Contributors include:\n"
84-
"Copyright (C) 2006-2007 Vladimir Paskov <[email protected]>\n"
85-
"Copyright (C) 2000-2002 Ville Syrjälä <[email protected]>,\n"
86-
" Bryn Davies <[email protected]>,\n"
87-
" Jonathan A. Davis <[email protected]>,\n"
88-
" Jeremy Tan <[email protected]>");
89-
90-
PluginConfig * get_config() { return &plugin_cfg; }
71+
EXPORT GlobalHotkeys aud_plugin_instance;
72+
PluginConfig plugin_cfg_gtk_global_hk;
73+
74+
const char GlobalHotkeys::about[] =
75+
N_("Global Hotkey Plugin\n"
76+
"Control the player with global key combinations or multimedia "
77+
"keys.\n\n"
78+
"Copyright (C) 2007-2008 Sascha Hlusiak <[email protected]>\n\n"
79+
"Contributors include:\n"
80+
"Copyright (C) 2020 Domen Mori <[email protected]>\n"
81+
"Copyright (C) 2006-2007 Vladimir Paskov <[email protected]>\n"
82+
"Copyright (C) 2000-2002 Ville Syrjälä <[email protected]>,\n"
83+
" Bryn Davies <[email protected]>,\n"
84+
" Jonathan A. Davis <[email protected]>,\n"
85+
" Jeremy Tan <[email protected]>");
86+
87+
PluginConfig * get_config() { return &plugin_cfg_gtk_global_hk; }
9188

9289
/*
9390
* plugin activated
@@ -104,8 +101,9 @@ bool GlobalHotkeys::init()
104101
}
105102
#ifdef _WIN32
106103
win_init();
107-
#endif
104+
#else
108105
setup_filter();
106+
#endif
109107
load_config();
110108
grab_keys();
111109
return true;
@@ -296,10 +294,9 @@ gboolean handle_keyevent(EVENT event)
296294

297295
void load_defaults()
298296
{
299-
AUDDBG("lHotkeyFlow:Entry, loading defaults.");
300297
HotkeyConfiguration * hotkey;
301298

302-
hotkey = &(plugin_cfg.first);
299+
hotkey = &(plugin_cfg_gtk_global_hk.first);
303300

304301
Hotkey::add_hotkey(&hotkey, OS_KEY_AudioPrev, 0, TYPE_KEY,
305302
EVENT_PREV_TRACK);
@@ -329,7 +326,7 @@ void load_config()
329326
HotkeyConfiguration * hotkey;
330327
int i, max;
331328

332-
hotkey = &(plugin_cfg.first);
329+
hotkey = &(plugin_cfg_gtk_global_hk.first);
333330
hotkey->next = nullptr;
334331
hotkey->key = 0;
335332
hotkey->mask = 0;
@@ -378,7 +375,7 @@ void save_config()
378375
int max;
379376
HotkeyConfiguration * hotkey;
380377

381-
hotkey = &(plugin_cfg.first);
378+
hotkey = &(plugin_cfg_gtk_global_hk.first);
382379
max = 0;
383380
while (hotkey)
384381
{
@@ -411,14 +408,17 @@ void save_config()
411408

412409
void GlobalHotkeys::cleanup()
413410
{
411+
#ifdef _WIN32
412+
system_up_and_running = false;
413+
#endif
414414
#ifdef BUILT_FROM_CMAKE
415+
AUDWARN("Cleanup of globalHotkeys");
415416
audlog::unsubscribe(&DCustomLogger::go);
416417
#endif
417-
418418
HotkeyConfiguration * hotkey;
419419
ungrab_keys();
420420
release_filter();
421-
hotkey = &(plugin_cfg.first);
421+
hotkey = &(plugin_cfg_gtk_global_hk.first);
422422
hotkey = hotkey->next;
423423
while (hotkey)
424424
{
@@ -427,8 +427,8 @@ void GlobalHotkeys::cleanup()
427427
hotkey = hotkey->next;
428428
g_free(old);
429429
}
430-
plugin_cfg.first.next = nullptr;
431-
plugin_cfg.first.key = 0;
432-
plugin_cfg.first.event = (EVENT)0;
433-
plugin_cfg.first.mask = 0;
430+
plugin_cfg_gtk_global_hk.first.next = nullptr;
431+
plugin_cfg_gtk_global_hk.first.key = 0;
432+
plugin_cfg_gtk_global_hk.first.event = (EVENT)0;
433+
plugin_cfg_gtk_global_hk.first.mask = 0;
434434
}

0 commit comments

Comments
 (0)