| 1 |
/* |
| 2 |
* libkysdk-shortcut's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2025, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: ShaoShuai Tian <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "libkyshortcut.h" |
| 24 |
#include "kglobalshortcut.h" |
| 25 |
|
| 26 |
#define KEYBINDINGS_DESKTOP_SCHEMA "org.ukui.SettingsDaemon.plugins.media-keys" |
| 27 |
#define KEYBINDINGS_SYSTEM_SCHEMA "org.gnome.desktop.wm.keybindings" |
| 28 |
#define KEYBINDINGS_CUSTOM_SCHEMA "org.ukui.control-center.keybinding" |
| 29 |
#define KEYBINDINGS_CUSTOM_DIR "/org/ukui/desktop/keybindings/" |
| 30 |
#define ACTION_KEY "action" |
| 31 |
#define BINDING_KEY "binding" |
| 32 |
#define NAME_KEY "name" |
| 33 |
#define DEFAULT_BINDING "disable" |
| 34 |
#define DEFAULT_SHORTCUT "defaultShortcut" |
| 35 |
#define DEFAULT_SHORTCUT_SCHEMA "org.ukui.control-center" |
| 36 |
#define MAX_CUSTOM_SHORTCUTS 1000 |
| 37 |
|
| 38 |
/*******************************KDK FUNC*****************************************/ |
| 39 |
|
| 40 |
int kdk_shortcut_create_global_shortcut(const char *name, const char *key, const char *action) |
| 41 |
{ |
| 42 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 43 |
return kGlobalShortcut.creatGlobalShortcut(name, key, action); |
| 44 |
} |
| 45 |
|
| 46 |
int kdk_shortcut_delete_global_shortcut(const char *name) |
| 47 |
{ |
| 48 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 49 |
return kGlobalShortcut.deleteGlobalShortcut(name); |
| 50 |
} |
| 51 |
|
| 52 |
int kdk_shortcut_global_shortcut_is_available(const char *key) |
| 53 |
{ |
| 54 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 55 |
return kGlobalShortcut.globalShortcutIsAvailable(key); |
| 56 |
} |
| 57 |
|
| 58 |
int kdk_shortcut_set_global_shortcut(const char *name, const char *key, const char *action) |
| 59 |
{ |
| 60 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 61 |
return kGlobalShortcut.setGlobalShortcut(name, key, action); |
| 62 |
} |
| 63 |
|
| 64 |
KYSDKGlobalShortcutInfoList *kdk_shortcut_get_global_shortcuts() |
| 65 |
{ |
| 66 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 67 |
return kGlobalShortcut.getGlobalShortcuts(); |
| 68 |
} |
| 69 |
|
| 70 |
KYSDKGlobalShortcutInfoList *kdk_shortcut_get_global_shortcuts_by_key(const char *key) |
| 71 |
{ |
| 72 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 73 |
return kGlobalShortcut.getGlobalShortcutByKey(key); |
| 74 |
} |
| 75 |
|
| 76 |
void kdk_shortcut_destroy_info_list(KYSDKGlobalShortcutInfoList *list) |
| 77 |
{ |
| 78 |
if (NULL == list) |
| 79 |
return; |
| 80 |
|
| 81 |
KYSDKGlobalShortcutInfoList *tmp = nullptr; |
| 82 |
while (list) |
| 83 |
{ |
| 84 |
tmp = list; |
| 85 |
list = list->next; |
| 86 |
|
| 87 |
if (tmp->data->name) |
| 88 |
free(tmp->data->name); |
| 89 |
if (tmp->data->action) |
| 90 |
free(tmp->data->action); |
| 91 |
free(tmp->data); |
| 92 |
free(tmp); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
const char *kdk_shortcut_key_combination_to_string(unsigned int key) |
| 97 |
{ |
| 98 |
static QByteArray result; |
| 99 |
result.clear(); |
| 100 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 101 |
result = kGlobalShortcut.numberToKey(key).toLatin1(); |
| 102 |
return result.constData(); |
| 103 |
} |
| 104 |
|
| 105 |
unsigned int kdk_shortcut_string_to_key_combination(const char *key) |
| 106 |
{ |
| 107 |
kdk::KGlobalShortcut kGlobalShortcut; |
| 108 |
return kGlobalShortcut.keyToNumber(key); |
| 109 |
} |