rofi 1.7.5
help-keys.c
Go to the documentation of this file.
1/*
2 * rofi
3 *
4 * MIT/X11 License
5 * Copyright © 2013-2022 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 "modes/help-keys.h"
42#include "helper.h"
43#include "rofi.h"
44#include "settings.h"
45#include "widgets/textbox.h"
46#include "xrmoptions.h"
47
48typedef struct {
49 char **messages;
50 unsigned int messages_length;
52
56
57static int help_keys_mode_init(Mode *sw) {
58 if (mode_get_private_data(sw) == NULL) {
59 KeysHelpModePrivateData *pd = g_malloc0(sizeof(*pd));
60 mode_set_private_data(sw, (void *)pd);
61 get_apps(pd);
62 }
63 return TRUE;
64}
65
66static ModeMode
67help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv,
68 G_GNUC_UNUSED char **input,
69 G_GNUC_UNUSED unsigned int selected_line) {
70 if (mretv & MENU_CUSTOM_COMMAND) {
71 int retv = (mretv & MENU_LOWER_MASK);
72 return retv;
73 }
74 return MODE_EXIT;
75}
76static void help_keys_mode_destroy(Mode *sw) {
79 if (rmpd != NULL) {
80 g_strfreev(rmpd->messages);
81 g_free(rmpd);
82 mode_set_private_data(sw, NULL);
83 }
84}
85
86static char *_get_display_value(const Mode *sw, unsigned int selected_line,
87 int *state, G_GNUC_UNUSED GList **list,
88 int get_entry) {
91 *state |= MARKUP;
92 if (!get_entry) {
93 return NULL;
94 }
95 return g_strdup(pd->messages[selected_line]);
96}
97static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens,
98 unsigned int index) {
101 return helper_token_match(tokens, rmpd->messages[index]);
102}
103
104static unsigned int help_keys_mode_get_num_entries(const Mode *sw) {
105 const KeysHelpModePrivateData *pd =
107 return pd->messages_length;
108}
109
110#include "mode-private.h"
112 .cfg_name_key = "display-keys",
113 ._init = help_keys_mode_init,
114 ._get_num_entries = help_keys_mode_get_num_entries,
115 ._result = help_keys_mode_result,
116 ._destroy = help_keys_mode_destroy,
117 ._token_match = help_keys_token_match,
118 ._get_completion = NULL,
119 ._get_display_value = _get_display_value,
120 .private_data = NULL,
121 .free = NULL};
char ** config_parser_return_display_help(unsigned int *length)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
Definition helper.c:518
Mode help_keys_mode
Definition help-keys.c:111
void * mode_get_private_data(const Mode *mode)
Definition mode.c:159
void mode_set_private_data(Mode *mode, void *pd)
Definition mode.c:164
ModeMode
Definition mode.h:49
@ MENU_CUSTOM_COMMAND
Definition mode.h:79
@ MENU_LOWER_MASK
Definition mode.h:87
@ MODE_EXIT
Definition mode.h:51
@ MARKUP
Definition textbox.h:110
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:67
static unsigned int help_keys_mode_get_num_entries(const Mode *sw)
Definition help-keys.c:104
static void help_keys_mode_destroy(Mode *sw)
Definition help-keys.c:76
static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens, unsigned int index)
Definition help-keys.c:97
static int help_keys_mode_init(Mode *sw)
Definition help-keys.c:57
static void get_apps(KeysHelpModePrivateData *pd)
Definition help-keys.c:53
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:86
unsigned int messages_length
Definition help-keys.c:50
char * name