rofi  1.5.4
help-keys.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2017 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 <stdlib.h>
30 #include <stdio.h>
31 
32 #include <unistd.h>
33 #include <limits.h>
34 #include <signal.h>
35 #include <sys/types.h>
36 #include <dirent.h>
37 #include <strings.h>
38 #include <string.h>
39 #include <errno.h>
40 
41 #include "rofi.h"
42 #include "settings.h"
43 #include "helper.h"
44 #include "xrmoptions.h"
45 #include "dialogs/help-keys.h"
46 #include "widgets/textbox.h"
47 
48 typedef struct
49 {
50  char **messages;
51  unsigned int messages_length;
53 
54 static void get_apps ( KeysHelpModePrivateData *pd )
55 {
57 }
58 
59 static int help_keys_mode_init ( Mode *sw )
60 {
61  if ( mode_get_private_data ( sw ) == NULL ) {
62  KeysHelpModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
63  mode_set_private_data ( sw, (void *) pd );
64  get_apps ( pd );
65  }
66  return TRUE;
67 }
68 
69 static ModeMode help_keys_mode_result ( G_GNUC_UNUSED Mode *sw,
70  int mretv,
71  G_GNUC_UNUSED char **input,
72  G_GNUC_UNUSED unsigned int selected_line )
73 {
74  ModeMode retv = MODE_EXIT;
75 
76  if ( mretv & MENU_NEXT ) {
77  retv = NEXT_DIALOG;
78  }
79  else if ( mretv & MENU_PREVIOUS ) {
80  retv = PREVIOUS_DIALOG;
81  }
82  else if ( mretv & MENU_QUICK_SWITCH ) {
83  retv = ( mretv & MENU_LOWER_MASK );
84  }
85  return retv;
86 }
87 static void help_keys_mode_destroy ( Mode *sw )
88 {
90  if ( rmpd != NULL ) {
91  g_strfreev ( rmpd->messages );
92  g_free ( rmpd );
93  mode_set_private_data ( sw, NULL );
94  }
95 }
96 
97 static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry )
98 {
100  *state |= MARKUP;
101  if ( !get_entry ) {
102  return NULL;
103  }
104  return g_strdup ( pd->messages[selected_line] );
105 }
106 static int help_keys_token_match ( const Mode *data,
107  rofi_int_matcher **tokens,
108  unsigned int index
109  )
110 {
112  return helper_token_match ( tokens, rmpd->messages[index] );
113 }
114 
115 static unsigned int help_keys_mode_get_num_entries ( const Mode *sw )
116 {
118  return pd->messages_length;
119 }
120 
121 #include "mode-private.h"
123 {
124  .name = "keys",
125  .cfg_name_key = "display-keys",
126  ._init = help_keys_mode_init,
127  ._get_num_entries = help_keys_mode_get_num_entries,
128  ._result = help_keys_mode_result,
129  ._destroy = help_keys_mode_destroy,
130  ._token_match = help_keys_token_match,
131  ._get_completion = NULL,
132  ._get_display_value = _get_display_value,
133  .private_data = NULL,
134  .free = NULL
135 };
MENU_QUICK_SWITCH
@ MENU_QUICK_SWITCH
Definition: mode.h:79
xrmoptions.h
help_keys_mode_destroy
static void help_keys_mode_destroy(Mode *sw)
Definition: help-keys.c:87
rofi_mode::name
char * name
Definition: mode-private.h:156
settings.h
MARKUP
@ MARKUP
Definition: textbox.h:105
help_keys_mode_init
static int help_keys_mode_init(Mode *sw)
Definition: help-keys.c:59
rofi_int_matcher_t
Definition: rofi-types.h:235
mode_set_private_data
void mode_set_private_data(Mode *mode, void *pd)
Definition: mode.c:134
PREVIOUS_DIALOG
@ PREVIOUS_DIALOG
Definition: mode.h:58
KeysHelpModePrivateData
Definition: help-keys.c:49
MENU_PREVIOUS
@ MENU_PREVIOUS
Definition: mode.h:81
NEXT_DIALOG
@ NEXT_DIALOG
Definition: mode.h:54
KeysHelpModePrivateData::messages_length
unsigned int messages_length
Definition: help-keys.c:51
mode-private.h
MODE_EXIT
@ MODE_EXIT
Definition: mode.h:52
help_keys_token_match
static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens, unsigned int index)
Definition: help-keys.c:106
help_keys_mode
Mode help_keys_mode
Definition: help-keys.c:122
help-keys.h
config_parser_return_display_help
char ** config_parser_return_display_help(unsigned int *length)
Definition: xrmoptions.c:807
rofi_mode
Definition: mode-private.h:152
rofi.h
help_keys_mode_result
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
mode_get_private_data
void * mode_get_private_data(const Mode *mode)
Definition: mode.c:128
MENU_NEXT
@ MENU_NEXT
Definition: mode.h:73
get_apps
static void get_apps(KeysHelpModePrivateData *pd)
Definition: help-keys.c:54
helper_token_match
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
Definition: helper.c:445
textbox.h
ModeMode
ModeMode
Definition: mode.h:50
MENU_LOWER_MASK
@ MENU_LOWER_MASK
Definition: mode.h:85
helper.h
KeysHelpModePrivateData::messages
char ** messages
Definition: help-keys.c:50
_get_display_value
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:97
help_keys_mode_get_num_entries
static unsigned int help_keys_mode_get_num_entries(const Mode *sw)
Definition: help-keys.c:115