29 #define G_LOG_DOMAIN "Dialogs.Combi" 39 #include <pango/pango.h> 70 const char *
const sep =
",#";
72 for (
char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL;
73 token = strtok_r ( NULL, sep, &savept ) ) {
92 g_warning (
"Invalid script switcher: %s", token );
98 g_free ( switcher_str );
107 pd->starts = g_malloc0 (
sizeof (
int ) * pd->num_switchers );
108 pd->lengths = g_malloc0 (
sizeof (
int ) * pd->num_switchers );
109 for (
unsigned int i = 0; i < pd->num_switchers; i++ ) {
110 if ( !
mode_init ( pd->switchers[i].mode ) ) {
114 if ( pd->cmd_list_length == 0 ) {
115 pd->cmd_list_length = 0;
116 for (
unsigned int i = 0; i < pd->num_switchers; i++ ) {
118 pd->starts[i] = pd->cmd_list_length;
119 pd->lengths[i] = length;
120 pd->cmd_list_length += length;
129 unsigned int length = 0;
157 if ( input[0][0] ==
'!' ) {
159 char *eob = strchrnul ( input[0],
' ' );
160 ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1;
161 if ( bang_len > 0 ) {
162 for (
unsigned i = 0; switcher == -1 && i < pd->
num_switchers; i++ ) {
164 size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
165 if ( (
size_t) bang_len <= mode_name_len &&
utf8_strncmp ( &input[0][1], mode_name, bang_len ) == 0 ) {
170 if ( switcher >= 0 ) {
171 if ( eob[0] ==
' ' ) {
174 selected_line - pd->
starts[switcher] );
184 if ( selected_line >= pd->
starts[i] &&
204 static char *
combi_mgrv (
const Mode *sw,
unsigned int selected_line,
int *state, GList **attr_list,
int get_entry )
209 if ( selected_line >= pd->
starts[i] && selected_line < ( pd->
starts[i] + pd->
lengths[i] ) ) {
217 if ( selected_line >= pd->
starts[i] && selected_line < ( pd->
starts[i] + pd->
lengths[i] ) ) {
222 retv = g_strdup_printf (
"%s %s", dname, str );
226 if ( attr_list != NULL ) {
230 PangoAttribute *pa = pango_attr_foreground_new (
234 pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
235 pa->end_index = strlen ( dname );
236 *attr_list = g_list_append ( *attr_list, pa );
257 g_assert_not_reached ();
279 if ( input != NULL && input[0] ==
'!' ) {
280 char *eob = strchrnul ( input,
' ' );
281 ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1;
282 if ( bang_len > 0 ) {
285 size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
286 if ( !( (
size_t) bang_len <= mode_name_len &&
utf8_strncmp ( &input[1], mode_name, bang_len ) == 0 ) ) {
291 if ( eob[0] ==
'\0' || eob[1] ==
'\0' ) {
294 return g_strdup ( eob + 1 );
297 return g_strdup ( input );
303 .cfg_name_key =
"display-combi",
313 .private_data = NULL,
static char * combi_preprocess_input(Mode *sw, const char *input)
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line)
static cairo_surface_t * combi_get_icon(const Mode *sw, unsigned int index, int height)
int utf8_strncmp(const char *a, const char *b, size_t n)
ThemeWidget * rofi_theme_find_widget(const char *name, const char *state, gboolean exact)
static int combi_mode_init(Mode *sw)
cairo_surface_t * mode_get_icon(const Mode *mode, unsigned int selected_line, int height)
Property * rofi_theme_find_property(ThemeWidget *widget, PropertyType type, const char *property, gboolean exact)
gboolean combi_hide_mode_prefix
static ModeMode combi_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
static void combi_mode_destroy(Mode *sw)
void * mode_get_private_data(const Mode *mode)
unsigned int num_switchers
Mode * rofi_collect_modi_search(const char *name)
void mode_destroy(Mode *mode)
static unsigned int combi_mode_get_num_entries(const Mode *sw)
unsigned int cmd_list_length
static void combi_mode_parse_switchers(Mode *sw)
unsigned int mode_get_num_entries(const Mode *mode)
char * mode_get_display_value(const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry)
const char * mode_get_name(const Mode *mode)
void mode_set_private_data(Mode *mode, void *pd)
Mode * script_switcher_parse_setup(const char *str)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
static char * combi_get_completion(const Mode *sw, unsigned int index)
const char * mode_get_display_name(const Mode *mode)
static char * combi_mgrv(const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry)
static int combi_mode_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
char * mode_get_completion(const Mode *mode, unsigned int selected_line)
int mode_init(Mode *mode)