rofi 1.7.9
help-keys.c
Go to the documentation of this file.
1/*
2 * rofi
3 *
4 * MIT/X11 License
5 * Copyright © 2013-2023 Qball Cow <qball@gmpclient.org>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28#include "config.h"
29#include <stdio.h>
30#include <stdlib.h>
31
32#include <dirent.h>
33#include <errno.h>
34#include <limits.h>
35#include <signal.h>
36#include <string.h>
37#include <strings.h>
38#include <sys/types.h>
39#include <unistd.h>
40
41#include "helper.h"
42#include "modes/help-keys.h"
43#include "rofi.h"
44#include "settings.h"
45#include "widgets/textbox.h"
46#include "xrmoptions.h"
47
48typedef struct {
50 char **messages;
52 unsigned int messages_length;
54
58
59static int help_keys_mode_init(Mode *sw) {
60 if (mode_get_private_data(sw) == NULL) {
61 KeysHelpModePrivateData *pd = g_malloc0(sizeof(*pd));
62 mode_set_private_data(sw, (void *)pd);
63 get_apps(pd);
64 }
65 return TRUE;
66}
67
68static ModeMode
69help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv,
70 G_GNUC_UNUSED char **input,
71 G_GNUC_UNUSED unsigned int selected_line) {
72 if (mretv & MENU_CUSTOM_COMMAND) {
73 int retv = (mretv & MENU_LOWER_MASK);
74 return retv;
75 }
76 return MODE_EXIT;
77}
78static void help_keys_mode_destroy(Mode *sw) {
81 if (rmpd != NULL) {
82 g_strfreev(rmpd->messages);
83 g_free(rmpd);
84 mode_set_private_data(sw, NULL);
85 }
86}
87
88static char *_get_display_value(const Mode *sw, unsigned int selected_line,
89 int *state, G_GNUC_UNUSED GList **list,
90 int get_entry) {
93 *state |= MARKUP;
94 if (!get_entry) {
95 return NULL;
96 }
97 return g_strdup(pd->messages[selected_line]);
98}
99static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens,
100 unsigned int index) {
103 return helper_token_match(tokens, rmpd->messages[index]);
104}
105
106static unsigned int help_keys_mode_get_num_entries(const Mode *sw) {
107 const KeysHelpModePrivateData *pd =
109 return pd->messages_length;
110}
111
112#include "mode-private.h"
113Mode help_keys_mode = {.name = "keys",
114 .cfg_name_key = "display-keys",
115 ._init = help_keys_mode_init,
116 ._get_num_entries = help_keys_mode_get_num_entries,
117 ._result = help_keys_mode_result,
118 ._destroy = help_keys_mode_destroy,
119 ._token_match = help_keys_token_match,
120 ._get_completion = NULL,
121 ._get_display_value = _get_display_value,
122 .private_data = NULL,
123 .free = NULL,
124 .type = MODE_TYPE_SWITCHER};
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
char ** config_parser_return_display_help(unsigned int *length)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
Definition helper.c:542
Mode help_keys_mode
Definition help-keys.c:113
struct rofi_mode Mode
Definition mode.h:49
void * mode_get_private_data(const Mode *mode)
Definition mode.c:176
void mode_set_private_data(Mode *mode, void *pd)
Definition mode.c:181
ModeMode
Definition mode.h:54
@ MENU_CUSTOM_COMMAND
Definition mode.h:84
@ MENU_LOWER_MASK
Definition mode.h:92
@ MODE_EXIT
Definition mode.h:56
@ MARKUP
Definition textbox.h:114
static ModeMode help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv, G_GNUC_UNUSED char **input, G_GNUC_UNUSED unsigned int selected_line)
Definition help-keys.c:69
static unsigned int help_keys_mode_get_num_entries(const Mode *sw)
Definition help-keys.c:106
static void help_keys_mode_destroy(Mode *sw)
Definition help-keys.c:78
static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens, unsigned int index)
Definition help-keys.c:99
static int help_keys_mode_init(Mode *sw)
Definition help-keys.c:59
static void get_apps(KeysHelpModePrivateData *pd)
Definition help-keys.c:55
static char * _get_display_value(const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry)
Definition help-keys.c:88
@ MODE_TYPE_SWITCHER
struct rofi_int_matcher_t rofi_int_matcher
unsigned int messages_length
Definition help-keys.c:52