rofi  1.5.4
mode.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 <stdio.h>
29 #include <glib.h>
30 #include <string.h>
31 #include "rofi.h"
32 #include "xrmoptions.h"
33 #include "mode.h"
34 
35 // This one should only be in mode implementations.
36 #include "mode-private.h"
42 int mode_init ( Mode *mode )
43 {
44  g_return_val_if_fail ( mode != NULL, FALSE );
45  g_return_val_if_fail ( mode->_init != NULL, FALSE );
46  return mode->_init ( mode );
47 }
48 
49 void mode_destroy ( Mode *mode )
50 {
51  g_assert ( mode != NULL );
52  g_assert ( mode->_destroy != NULL );
53  mode->_destroy ( mode );
54 }
55 
56 unsigned int mode_get_num_entries ( const Mode *mode )
57 {
58  g_assert ( mode != NULL );
59  g_assert ( mode->_get_num_entries != NULL );
60  return mode->_get_num_entries ( mode );
61 }
62 
63 char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry )
64 {
65  g_assert ( mode != NULL );
66  g_assert ( state != NULL );
67  g_assert ( mode->_get_display_value != NULL );
68 
69  return mode->_get_display_value ( mode, selected_line, state, attribute_list, get_entry );
70 }
71 
72 cairo_surface_t * mode_get_icon ( const Mode *mode, unsigned int selected_line, int height )
73 {
74  g_assert ( mode != NULL );
75 
76  if ( mode->_get_icon != NULL ) {
77  return mode->_get_icon ( mode, selected_line, height );
78  }
79  else {
80  return NULL;
81  }
82 }
83 
84 char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
85 {
86  g_assert ( mode != NULL );
87  if ( mode->_get_completion != NULL ) {
88  return mode->_get_completion ( mode, selected_line );
89  }
90  else {
91  int state;
92  g_assert ( mode->_get_display_value != NULL );
93  return mode->_get_display_value ( mode, selected_line, &state, NULL, TRUE );
94  }
95 }
96 
97 ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
98 {
99  g_assert ( mode != NULL );
100  g_assert ( mode->_result != NULL );
101  g_assert ( input != NULL );
102  return mode->_result ( mode, menu_retv, input, selected_line );
103 }
104 
105 int mode_token_match ( const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line )
106 {
107  g_assert ( mode != NULL );
108  g_assert ( mode->_token_match != NULL );
109  return mode->_token_match ( mode, tokens, selected_line );
110 }
111 
112 const char *mode_get_name ( const Mode *mode )
113 {
114  g_assert ( mode != NULL );
115  return mode->name;
116 }
117 
118 void mode_free ( Mode **mode )
119 {
120  g_assert ( mode != NULL );
121  g_assert ( ( *mode ) != NULL );
122  if ( ( *mode )->free != NULL ) {
123  ( *mode )->free ( *mode );
124  }
125  ( *mode ) = NULL;
126 }
127 
128 void *mode_get_private_data ( const Mode *mode )
129 {
130  g_assert ( mode != NULL );
131  return mode->private_data;
132 }
133 
134 void mode_set_private_data ( Mode *mode, void *pd )
135 {
136  g_assert ( mode != NULL );
137  if ( pd != NULL ) {
138  g_assert ( mode->private_data == NULL );
139  }
140  mode->private_data = pd;
141 }
142 
143 const char *mode_get_display_name ( const Mode *mode )
144 {
145  if ( mode->display_name != NULL ) {
146  return mode->display_name;
147  }
148  return mode->name;
149 }
150 
151 void mode_set_config ( Mode *mode )
152 {
153  snprintf ( mode->cfg_name_key, 128, "display-%s", mode->name );
154  config_parser_add_option ( xrm_String, mode->cfg_name_key, (void * *) &( mode->display_name ), "The display name of this browser" );
155 }
156 
157 char * mode_preprocess_input ( Mode *mode, const char *input )
158 {
159  if ( mode->_preprocess_input ) {
160  return mode->_preprocess_input ( mode, input );
161  }
162  return g_strdup ( input );
163 }
164 char *mode_get_message ( const Mode *mode )
165 {
166  if ( mode->_get_message ) {
167  return mode->_get_message ( mode );
168  }
169  return NULL;
170 }
xrmoptions.h
mode_get_completion
char * mode_get_completion(const Mode *mode, unsigned int selected_line)
Definition: mode.c:84
rofi_mode::name
char * name
Definition: mode-private.h:156
mode_token_match
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line)
Definition: mode.c:105
rofi_mode::_init
__mode_init _init
Definition: mode-private.h:164
rofi_int_matcher_t
Definition: rofi-types.h:235
mode_get_icon
cairo_surface_t * mode_get_icon(const Mode *mode, unsigned int selected_line, int height)
Definition: mode.c:72
mode_set_private_data
void mode_set_private_data(Mode *mode, void *pd)
Definition: mode.c:134
mode.h
rofi_mode::_token_match
_mode_token_match _token_match
Definition: mode-private.h:172
mode_init
int mode_init(Mode *mode)
Definition: mode.c:42
rofi_mode::_get_icon
_mode_get_icon _get_icon
Definition: mode-private.h:176
rofi_mode::_preprocess_input
_mode_preprocess_input _preprocess_input
Definition: mode-private.h:180
mode-private.h
mode_get_name
const char * mode_get_name(const Mode *mode)
Definition: mode.c:112
mode_free
void mode_free(Mode **mode)
Definition: mode.c:118
mode_get_num_entries
unsigned int mode_get_num_entries(const Mode *mode)
Definition: mode.c:56
mode_preprocess_input
char * mode_preprocess_input(Mode *mode, const char *input)
Definition: mode.c:157
mode_destroy
void mode_destroy(Mode *mode)
Definition: mode.c:49
rofi_mode
Definition: mode-private.h:152
rofi.h
rofi_mode::private_data
void * private_data
Definition: mode-private.h:185
config_parser_add_option
void config_parser_add_option(XrmOptionType type, const char *key, void **value, const char *comment)
Definition: xrmoptions.c:230
xrm_String
@ xrm_String
Definition: xrmoptions.h:72
mode_get_display_name
const char * mode_get_display_name(const Mode *mode)
Definition: mode.c:143
rofi_mode::_destroy
__mode_destroy _destroy
Definition: mode-private.h:166
rofi_mode::display_name
char * display_name
Definition: mode-private.h:158
mode_get_private_data
void * mode_get_private_data(const Mode *mode)
Definition: mode.c:128
rofi_mode::_get_display_value
_mode_get_display_value _get_display_value
Definition: mode-private.h:174
mode_get_display_value
char * mode_get_display_value(const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry)
Definition: mode.c:63
ModeMode
ModeMode
Definition: mode.h:50
mode_get_message
char * mode_get_message(const Mode *mode)
Definition: mode.c:164
mode_result
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
Definition: mode.c:97
rofi_mode::cfg_name_key
char cfg_name_key[128]
Definition: mode-private.h:157
rofi_mode::_result
_mode_result _result
Definition: mode-private.h:170
rofi_mode::_get_completion
_mode_get_completion _get_completion
Definition: mode-private.h:178
rofi_mode::_get_message
_mode_get_message _get_message
Definition: mode-private.h:182
mode_set_config
void mode_set_config(Mode *mode)
Definition: mode.c:151
rofi_mode::_get_num_entries
__mode_get_num_entries _get_num_entries
Definition: mode-private.h:168