| 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 |
#ifndef LIBKYSHORTCUT_H |
| 24 |
#define LIBKYSHORTCUT_H |
| 25 |
|
| 26 |
#ifdef __cplusplus |
| 27 |
extern "C" |
| 28 |
{ |
| 29 |
#endif |
| 30 |
|
| 31 |
/** @defgroup ShortcutModule |
| 32 |
* @{ |
| 33 |
*/ |
| 34 |
|
| 35 |
/** |
| 36 |
* @file libkyshortcut.h |
| 37 |
* @author tianshaoshuai ([email protected]) |
| 38 |
* @brief 提供快捷键管理功能 |
| 39 |
* @date 2025-04-17 |
| 40 |
* |
| 41 |
* @copyright Copyright (c) 2025 |
| 42 |
* @since 3.0.1.0 |
| 43 |
*/ |
| 44 |
|
| 45 |
#include "libkykeymap.h" |
| 46 |
|
| 47 |
#define KYSDK_SUCCESS 0 |
| 48 |
#define KYSDK_SHORTCUT_NAME_ERROR -1 // 快捷键名错误 |
| 49 |
#define KYSDK_SHORTCUT_KEY_ERROR -2 // 快捷键错误 |
| 50 |
#define KYSDK_SHORTCUT_ACTION_ERROR -3 // 快捷键命令错误 |
| 51 |
#define KYSDK_SHORTCUT_NOT_EXISTS -4 // 快捷键不存在 |
| 52 |
#define KYSDK_SHORTCUT_EXISTED -5 // 快捷键已存在 |
| 53 |
|
| 54 |
typedef struct _KYSDKGlobalShortcutInfo |
| 55 |
{ |
| 56 |
char *compenteName; // 所属组件 |
| 57 |
char *name; // 快捷键名称 |
| 58 |
unsigned int keys[4]; // 快捷键字符串组合 |
| 59 |
char *action; // 执行程序,仅组件kysdk_bindings时有值 |
| 60 |
} KYSDKGlobalShortcutInfo; |
| 61 |
|
| 62 |
typedef struct _KYSDKGlobalShortcutInfoList |
| 63 |
{ |
| 64 |
KYSDKGlobalShortcutInfo *data; |
| 65 |
struct _KYSDKGlobalShortcutInfoList *next; |
| 66 |
} KYSDKGlobalShortcutInfoList; |
| 67 |
|
| 68 |
/** |
| 69 |
* @brief 创建一个新的全局快捷键 |
| 70 |
* |
| 71 |
* @param name 快捷键名称(唯一) |
| 72 |
* @param key_sequence 快捷键,例如Ctrl + P |
| 73 |
* @param action 应用的desktop文件,或应用的执行命令(可执行程序传绝对路径) |
| 74 |
* @return int 成功返回0,失败返回错误码 |
| 75 |
* @since 3.0.1.0 |
| 76 |
*/ |
| 77 |
int kdk_shortcut_create_global_shortcut(const char *name, const char *key, const char *action); |
| 78 |
|
| 79 |
/** |
| 80 |
* @brief 删除全局快捷键 |
| 81 |
* |
| 82 |
* @param name 快捷键名称 |
| 83 |
* @return int 成功返回0,失败返回错误码 |
| 84 |
* @since 3.0.1.0 |
| 85 |
*/ |
| 86 |
int kdk_shortcut_delete_global_shortcut(const char *name); |
| 87 |
|
| 88 |
/** |
| 89 |
* @brief 检测全局快捷键是否可用 |
| 90 |
* |
| 91 |
* @param key_sequence 快捷键 |
| 92 |
* @return int 成功返回0,失败返回错误码 |
| 93 |
* @since 3.0.1.0 |
| 94 |
*/ |
| 95 |
int kdk_shortcut_global_shortcut_is_available(const char *key); |
| 96 |
|
| 97 |
/** |
| 98 |
* @brief 修改全局快捷键 |
| 99 |
* |
| 100 |
* @param name 快捷键名称,全局唯一的名称 |
| 101 |
* @param key_sequence 快捷键,传空字符则不修改 |
| 102 |
* @param action 执行命令,传空字符则不修改 |
| 103 |
* @return int 成功返回0,失败返回错误码 |
| 104 |
* @since 3.0.1.0 |
| 105 |
*/ |
| 106 |
int kdk_shortcut_set_global_shortcut(const char *name, const char *key, const char *action); |
| 107 |
|
| 108 |
/** |
| 109 |
* @brief 获取全局快捷键信息 |
| 110 |
* |
| 111 |
* @return GlobalKeyEntryList* 快捷键信息链表 |
| 112 |
* @since 3.0.1.0 |
| 113 |
*/ |
| 114 |
KYSDKGlobalShortcutInfoList *kdk_shortcut_get_global_shortcuts(); |
| 115 |
|
| 116 |
/** |
| 117 |
* @brief 获取快捷键信息 |
| 118 |
* |
| 119 |
* @param key_sequence 快捷键 |
| 120 |
* @return GlobalKeyEntryList* 快捷键信息链表 |
| 121 |
* @since 3.0.1.0 |
| 122 |
*/ |
| 123 |
KYSDKGlobalShortcutInfoList *kdk_shortcut_get_global_shortcuts_by_key(const char *key); |
| 124 |
|
| 125 |
/** |
| 126 |
* @brief 销毁GlobalShortcutInfoList列表 |
| 127 |
* |
| 128 |
* @since 3.0.1.0 |
| 129 |
*/ |
| 130 |
void kdk_shortcut_destroy_info_list(KYSDKGlobalShortcutInfoList *list); |
| 131 |
|
| 132 |
/** |
| 133 |
* @brief 键值组合转换为字符串 |
| 134 |
* |
| 135 |
* @param key 键值组合, 控制键 + 功能键 |
| 136 |
* @return char* 组合字符串 |
| 137 |
* @since 3.0.1.0 |
| 138 |
*/ |
| 139 |
const char *kdk_shortcut_key_combination_to_string(unsigned int key); |
| 140 |
|
| 141 |
/** |
| 142 |
* @brief 字符串转换为键值组合 |
| 143 |
* |
| 144 |
* @param key 组合字符串 |
| 145 |
* @return unsigned int 键值组合 |
| 146 |
* @since 3.0.1.0 |
| 147 |
*/ |
| 148 |
unsigned int kdk_shortcut_string_to_key_combination(const char *key); |
| 149 |
|
| 150 |
#ifdef __cplusplus |
| 151 |
} |
| 152 |
#endif |
| 153 |
|
| 154 |
#endif // LIBKYSHORTCUT_H |