2019-08-17 21:19:32 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Scoopta
|
|
|
|
* This file is part of Wofi
|
|
|
|
* Wofi is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Wofi is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Wofi. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wofi.h>
|
|
|
|
|
2019-09-27 02:24:48 -04:00
|
|
|
static const char* terminals[] = {"kitty", "termite", "gnome-terminal", "weston-terminal"};
|
|
|
|
|
2019-11-21 04:01:27 -05:00
|
|
|
enum matching_mode {
|
|
|
|
MATCHING_MODE_CONTAINS,
|
|
|
|
MATCHING_MODE_FUZZY
|
|
|
|
};
|
|
|
|
|
2019-08-17 21:19:32 -04:00
|
|
|
static uint64_t width, height;
|
|
|
|
static int64_t x, y;
|
|
|
|
static struct zwlr_layer_shell_v1* shell;
|
2019-08-19 20:34:12 -04:00
|
|
|
static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL;
|
2019-08-17 21:19:32 -04:00
|
|
|
static const gchar* filter;
|
2019-11-04 23:56:40 -05:00
|
|
|
static char* mode = NULL;
|
2019-08-27 00:19:59 -04:00
|
|
|
static time_t filter_time;
|
|
|
|
static int64_t filter_rate;
|
2019-08-28 03:58:45 -04:00
|
|
|
static bool allow_images, allow_markup;
|
2019-08-28 20:36:20 -04:00
|
|
|
static uint64_t image_size;
|
2019-08-28 23:14:38 -04:00
|
|
|
static char* cache_file = NULL;
|
2019-09-13 03:25:25 -04:00
|
|
|
static char* config_dir;
|
2019-11-19 01:16:06 -05:00
|
|
|
static bool mod_shift;
|
2019-11-19 01:13:14 -05:00
|
|
|
static bool mod_ctrl;
|
2019-09-27 02:24:48 -04:00
|
|
|
static char* terminal;
|
2019-10-13 01:24:35 -04:00
|
|
|
static GtkOrientation outer_orientation;
|
2019-11-04 20:46:39 -05:00
|
|
|
static bool exec_search;
|
2019-11-04 23:56:40 -05:00
|
|
|
static struct map* modes;
|
2019-11-21 04:01:27 -05:00
|
|
|
static enum matching_mode matching;
|
2019-11-25 17:56:46 -05:00
|
|
|
static bool insensitive;
|
2019-08-28 00:36:44 -04:00
|
|
|
|
2019-08-18 21:06:13 -04:00
|
|
|
struct node {
|
2019-11-13 04:17:45 -05:00
|
|
|
size_t action_count;
|
|
|
|
char* mode, **text, *search_text, **actions;
|
2019-11-04 23:56:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mode {
|
|
|
|
void (*mode_exec)(const gchar* cmd);
|
2019-08-18 23:49:12 -04:00
|
|
|
};
|
|
|
|
|
2019-08-17 21:19:32 -04:00
|
|
|
static void nop() {}
|
|
|
|
|
|
|
|
static void add_interface(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
|
|
|
|
(void) data;
|
|
|
|
if(strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
|
|
|
shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void config_surface(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t _width, uint32_t _height) {
|
|
|
|
(void) data;
|
|
|
|
(void) _width;
|
|
|
|
(void) _height;
|
|
|
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
|
|
|
zwlr_layer_surface_v1_set_size(surface, width, height);
|
|
|
|
zwlr_layer_surface_v1_set_keyboard_interactivity(surface, true);
|
|
|
|
if(x >= 0 && y >= 0) {
|
|
|
|
zwlr_layer_surface_v1_set_margin(surface, y, 0, 0, x);
|
|
|
|
zwlr_layer_surface_v1_set_anchor(surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_input(GtkSearchEntry* entry, gpointer data) {
|
2019-08-27 00:19:59 -04:00
|
|
|
(void) data;
|
|
|
|
if(utils_get_time_millis() - filter_time > filter_rate) {
|
|
|
|
filter = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
|
|
filter_time = utils_get_time_millis();
|
2019-08-28 22:33:08 -04:00
|
|
|
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
|
2019-11-21 04:01:27 -05:00
|
|
|
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
|
2019-08-27 00:19:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_search(GtkSearchEntry* entry, gpointer data) {
|
2019-08-19 20:34:12 -04:00
|
|
|
(void) data;
|
2019-08-17 21:19:32 -04:00
|
|
|
filter = gtk_entry_get_text(GTK_ENTRY(entry));
|
2019-08-28 22:33:08 -04:00
|
|
|
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
|
2019-11-21 04:01:27 -05:00
|
|
|
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
|
2019-08-17 21:19:32 -04:00
|
|
|
}
|
|
|
|
|
2019-11-04 23:56:40 -05:00
|
|
|
static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
|
2019-08-28 02:15:18 -04:00
|
|
|
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_set_name(box, "unselected");
|
2019-09-12 15:38:24 -04:00
|
|
|
GtkStyleContext* style = gtk_widget_get_style_context(box);
|
|
|
|
gtk_style_context_add_class(style, "entry");
|
2019-11-04 23:56:40 -05:00
|
|
|
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode);
|
2019-08-28 02:15:18 -04:00
|
|
|
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action);
|
|
|
|
if(allow_images) {
|
2019-11-21 01:05:28 -05:00
|
|
|
struct map* modes = map_init();
|
|
|
|
map_put(modes, "img", "true");
|
|
|
|
map_put(modes, "text", "true");
|
|
|
|
|
2019-08-28 02:15:18 -04:00
|
|
|
char* tmp = strdup(text);
|
|
|
|
char* mode = NULL;
|
|
|
|
|
2019-11-05 12:41:47 -05:00
|
|
|
if(strchr(tmp, ':') == NULL) {
|
|
|
|
mode = "text";
|
|
|
|
}
|
2019-11-05 01:41:53 -05:00
|
|
|
char* save_ptr;
|
|
|
|
char* str = strtok_r(tmp, ":", &save_ptr);
|
|
|
|
do {
|
2019-08-28 02:15:18 -04:00
|
|
|
if(mode == NULL) {
|
2019-11-21 01:05:28 -05:00
|
|
|
if(map_contains(modes, str)) {
|
|
|
|
mode = str;
|
|
|
|
} else {
|
|
|
|
char* start = (str - tmp) + text;
|
|
|
|
if(start != text) {
|
|
|
|
--start;
|
|
|
|
}
|
|
|
|
long end = strlen(str) + 1;
|
|
|
|
str = strdup(start);
|
|
|
|
*(str + end) = 0;
|
|
|
|
|
|
|
|
GtkWidget* label = gtk_label_new(str);
|
|
|
|
gtk_widget_set_name(label, "text");
|
|
|
|
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), label);
|
|
|
|
free(str);
|
|
|
|
}
|
2019-08-28 02:15:18 -04:00
|
|
|
} else {
|
|
|
|
if(strcmp(mode, "img") == 0) {
|
2019-11-05 01:41:53 -05:00
|
|
|
GdkPixbuf* buf = gdk_pixbuf_new_from_file(str, NULL);
|
2019-08-28 02:15:18 -04:00
|
|
|
int width = gdk_pixbuf_get_width(buf);
|
|
|
|
int height = gdk_pixbuf_get_height(buf);
|
|
|
|
if(height > width) {
|
2019-08-28 20:36:20 -04:00
|
|
|
float percent = (float) image_size / height;
|
|
|
|
GdkPixbuf* tmp = gdk_pixbuf_scale_simple(buf, width * percent, image_size, GDK_INTERP_BILINEAR);
|
2019-08-28 02:15:18 -04:00
|
|
|
g_object_unref(buf);
|
|
|
|
buf = tmp;
|
|
|
|
} else {
|
2019-08-28 20:36:20 -04:00
|
|
|
float percent = (float) image_size / width;
|
|
|
|
GdkPixbuf* tmp = gdk_pixbuf_scale_simple(buf, image_size, height * percent, GDK_INTERP_BILINEAR);
|
2019-08-28 02:15:18 -04:00
|
|
|
g_object_unref(buf);
|
|
|
|
buf = tmp;
|
|
|
|
}
|
|
|
|
GtkWidget* img = gtk_image_new_from_pixbuf(buf);
|
2019-09-01 23:07:15 -04:00
|
|
|
gtk_widget_set_name(img, "img");
|
2019-08-28 02:15:18 -04:00
|
|
|
gtk_container_add(GTK_CONTAINER(box), img);
|
|
|
|
} else if(strcmp(mode, "text") == 0) {
|
2019-11-05 01:41:53 -05:00
|
|
|
GtkWidget* label = gtk_label_new(str);
|
2019-09-01 23:07:15 -04:00
|
|
|
gtk_widget_set_name(label, "text");
|
2019-08-28 03:58:45 -04:00
|
|
|
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
|
2019-08-28 02:15:18 -04:00
|
|
|
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), label);
|
|
|
|
}
|
|
|
|
mode = NULL;
|
|
|
|
}
|
2019-11-05 01:41:53 -05:00
|
|
|
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
|
|
|
|
free(tmp);
|
2019-11-21 01:05:28 -05:00
|
|
|
map_free(modes);
|
2019-08-28 02:15:18 -04:00
|
|
|
} else {
|
|
|
|
GtkWidget* label = gtk_label_new(text);
|
2019-09-15 19:29:15 -04:00
|
|
|
gtk_widget_set_name(label, "text");
|
2019-08-28 03:58:45 -04:00
|
|
|
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
|
2019-08-28 02:15:18 -04:00
|
|
|
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), label);
|
|
|
|
}
|
2019-10-28 17:17:06 -04:00
|
|
|
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", search_text);
|
2019-08-28 02:15:18 -04:00
|
|
|
return box;
|
2019-08-18 23:49:12 -04:00
|
|
|
}
|
|
|
|
|
2019-11-05 01:41:53 -05:00
|
|
|
static char* get_cache_path(const gchar* mode) {
|
2019-08-28 23:14:38 -04:00
|
|
|
if(cache_file != NULL) {
|
2019-09-12 14:06:57 -04:00
|
|
|
return strdup(cache_file);
|
2019-08-28 23:14:38 -04:00
|
|
|
}
|
2019-08-18 23:49:12 -04:00
|
|
|
char* cache_path = getenv("XDG_CACHE_HOME");
|
|
|
|
if(cache_path == NULL) {
|
|
|
|
cache_path = utils_concat(3, getenv("HOME"), "/.cache/wofi-", mode);
|
|
|
|
} else {
|
|
|
|
cache_path = utils_concat(3, cache_path, "/wofi-", mode);
|
|
|
|
}
|
|
|
|
return cache_path;
|
|
|
|
}
|
|
|
|
|
2019-11-16 17:52:20 -05:00
|
|
|
static void execute_action(const gchar* mode, const gchar* cmd) {
|
2019-11-13 04:17:45 -05:00
|
|
|
struct mode* mode_ptr = map_get(modes, mode);
|
|
|
|
mode_ptr->mode_exec(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void activate_item(GtkFlowBox* flow_box, GtkFlowBoxChild* row, gpointer data) {
|
|
|
|
(void) flow_box;
|
|
|
|
(void) data;
|
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(row));
|
|
|
|
bool primary_action = GTK_IS_EXPANDER(box);
|
|
|
|
if(primary_action) {
|
|
|
|
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
|
|
|
|
}
|
2019-11-16 17:52:20 -05:00
|
|
|
execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
|
2019-11-13 04:17:45 -05:00
|
|
|
}
|
|
|
|
|
2019-11-19 22:14:30 -05:00
|
|
|
static void expand(GtkExpander* expander, gpointer data) {
|
|
|
|
(void) data;
|
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(expander));
|
|
|
|
gtk_widget_set_visible(box, !gtk_expander_get_expanded(expander));
|
|
|
|
}
|
|
|
|
|
2019-11-13 04:17:45 -05:00
|
|
|
static gboolean _insert_widget(gpointer data) {
|
|
|
|
struct node* node = data;
|
|
|
|
GtkWidget* parent;
|
|
|
|
if(node->action_count > 1) {
|
|
|
|
parent = gtk_expander_new("");
|
2019-11-19 22:14:30 -05:00
|
|
|
g_signal_connect(parent, "activate", G_CALLBACK(expand), NULL);
|
2019-11-13 04:17:45 -05:00
|
|
|
GtkWidget* box = create_label(node->mode, node->text[0], node->search_text, node->actions[0]);
|
|
|
|
gtk_expander_set_label_widget(GTK_EXPANDER(parent), box);
|
2019-11-19 22:14:30 -05:00
|
|
|
|
2019-11-13 04:17:45 -05:00
|
|
|
GtkWidget* exp_box = gtk_list_box_new();
|
2019-11-13 04:42:27 -05:00
|
|
|
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(exp_box), FALSE);
|
2019-11-13 04:17:45 -05:00
|
|
|
g_signal_connect(exp_box, "row-activated", G_CALLBACK(activate_item), NULL);
|
|
|
|
gtk_container_add(GTK_CONTAINER(parent), exp_box);
|
|
|
|
for(size_t count = 1; count < node->action_count; ++count) {
|
|
|
|
box = create_label(node->mode, node->text[count], node->search_text, node->actions[count]);
|
|
|
|
gtk_container_add(GTK_CONTAINER(exp_box), box);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parent = create_label(node->mode, node->text[0], node->search_text, node->actions[0]);
|
|
|
|
}
|
|
|
|
gtk_container_add(GTK_CONTAINER(inner_box), parent);
|
|
|
|
gtk_widget_show_all(parent);
|
|
|
|
|
2019-11-19 22:14:30 -05:00
|
|
|
if(GTK_IS_EXPANDER(parent)) {
|
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(parent));
|
|
|
|
gtk_widget_set_visible(box, FALSE);
|
|
|
|
}
|
|
|
|
|
2019-11-13 04:17:45 -05:00
|
|
|
free(node->mode);
|
|
|
|
for(size_t count = 0; count < node->action_count; ++count) {
|
|
|
|
free(node->text[count]);
|
|
|
|
}
|
|
|
|
free(node->text);
|
|
|
|
free(node->search_text);
|
|
|
|
for(size_t count = 0; count < node->action_count; ++count) {
|
|
|
|
free(node->actions[count]);
|
|
|
|
}
|
|
|
|
free(node->actions);
|
|
|
|
free(node);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-16 17:52:20 -05:00
|
|
|
void wofi_write_cache(const gchar* mode, const gchar* cmd) {
|
|
|
|
char* cache_path = get_cache_path(mode);
|
|
|
|
struct wl_list lines;
|
|
|
|
wl_list_init(&lines);
|
|
|
|
bool inc_count = false;
|
|
|
|
if(access(cache_path, R_OK) == 0) {
|
|
|
|
FILE* file = fopen(cache_path, "r");
|
|
|
|
char* line = NULL;
|
|
|
|
size_t size = 0;
|
|
|
|
while(getline(&line, &size, file) != -1) {
|
|
|
|
struct cache_line* node = malloc(sizeof(struct cache_line));
|
|
|
|
if(strstr(line, cmd) != NULL) {
|
|
|
|
uint64_t count = strtol(line, NULL, 10) + 1;
|
|
|
|
char num[6];
|
|
|
|
snprintf(num, 5, "%" PRIu64, count);
|
|
|
|
node->line = utils_concat(4, num, " ", cmd, "\n");
|
|
|
|
inc_count = true;
|
|
|
|
} else {
|
|
|
|
node->line = strdup(line);
|
|
|
|
}
|
|
|
|
wl_list_insert(&lines, &node->link);
|
|
|
|
}
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
if(!inc_count) {
|
|
|
|
struct cache_line* node = malloc(sizeof(struct cache_line));
|
|
|
|
node->line = utils_concat(3, "1 ", cmd, "\n");
|
|
|
|
wl_list_insert(&lines, &node->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* file = fopen(cache_path, "w");
|
|
|
|
struct cache_line* node, *tmp;
|
|
|
|
wl_list_for_each_safe(node, tmp, &lines, link) {
|
|
|
|
fwrite(node->line, 1, strlen(node->line), file);
|
|
|
|
free(node->line);
|
|
|
|
wl_list_remove(&node->link);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
free(cache_path);
|
|
|
|
}
|
|
|
|
|
2019-09-13 03:25:25 -04:00
|
|
|
struct wl_list* wofi_read_cache(char* mode) {
|
2019-08-18 23:49:12 -04:00
|
|
|
char* cache_path = get_cache_path(mode);
|
|
|
|
struct wl_list* cache = malloc(sizeof(struct wl_list));
|
|
|
|
wl_list_init(cache);
|
|
|
|
struct wl_list lines;
|
|
|
|
wl_list_init(&lines);
|
|
|
|
if(access(cache_path, R_OK) == 0) {
|
|
|
|
FILE* file = fopen(cache_path, "r");
|
|
|
|
char* line = NULL;
|
|
|
|
size_t size = 0;
|
|
|
|
while(getline(&line, &size, file) != -1) {
|
|
|
|
struct cache_line* node = malloc(sizeof(struct cache_line));
|
|
|
|
char* lf = strchr(line, '\n');
|
|
|
|
if(lf != NULL) {
|
|
|
|
*lf = 0;
|
|
|
|
}
|
|
|
|
node->line = strdup(line);
|
|
|
|
wl_list_insert(&lines, &node->link);
|
|
|
|
}
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
while(wl_list_length(&lines) > 0) {
|
2019-09-13 03:25:25 -04:00
|
|
|
uint64_t smallest = UINT64_MAX;
|
|
|
|
struct cache_line* node, *smallest_node = NULL;
|
2019-08-18 23:49:12 -04:00
|
|
|
wl_list_for_each(node, &lines, link) {
|
|
|
|
uint64_t num = strtol(node->line, NULL, 10);
|
2019-09-13 03:25:25 -04:00
|
|
|
if(num < smallest) {
|
|
|
|
smallest = num;
|
|
|
|
smallest_node = node;
|
2019-08-18 23:49:12 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-13 03:25:25 -04:00
|
|
|
char* tmp = strdup(strchr(smallest_node->line, ' ') + 1);
|
|
|
|
free(smallest_node->line);
|
|
|
|
smallest_node->line = tmp;
|
|
|
|
wl_list_remove(&smallest_node->link);
|
|
|
|
wl_list_insert(cache, &smallest_node->link);
|
2019-08-18 23:49:12 -04:00
|
|
|
}
|
|
|
|
free(cache_path);
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2019-11-13 04:17:45 -05:00
|
|
|
void wofi_insert_widget(char* mode, char** text, char* search_text, char** actions, size_t action_count) {
|
2019-08-28 23:43:47 -04:00
|
|
|
struct node* widget = malloc(sizeof(struct node));
|
2019-11-04 23:56:40 -05:00
|
|
|
widget->mode = strdup(mode);
|
2019-11-13 04:17:45 -05:00
|
|
|
widget->text = malloc(action_count * sizeof(char*));
|
|
|
|
for(size_t count = 0; count < action_count; ++count) {
|
|
|
|
widget->text[count] = strdup(text[count]);
|
|
|
|
}
|
2019-10-28 17:17:06 -04:00
|
|
|
widget->search_text = strdup(search_text);
|
2019-11-13 04:17:45 -05:00
|
|
|
widget->action_count = action_count;
|
|
|
|
widget->actions = malloc(action_count * sizeof(char*));
|
|
|
|
for(size_t count = 0; count < action_count; ++count) {
|
|
|
|
widget->actions[count] = strdup(actions[count]);
|
|
|
|
}
|
2019-08-28 23:43:47 -04:00
|
|
|
g_idle_add(_insert_widget, widget);
|
|
|
|
utils_sleep_millis(1);
|
|
|
|
}
|
|
|
|
|
2019-09-13 03:25:25 -04:00
|
|
|
bool wofi_allow_images() {
|
|
|
|
return allow_images;
|
2019-08-17 23:21:52 -04:00
|
|
|
}
|
|
|
|
|
2019-09-13 03:25:25 -04:00
|
|
|
uint64_t wofi_get_image_size() {
|
|
|
|
return image_size;
|
2019-09-12 00:00:26 -04:00
|
|
|
}
|
|
|
|
|
2019-11-19 01:16:06 -05:00
|
|
|
bool wofi_mod_shift() {
|
|
|
|
return mod_shift;
|
2019-09-27 02:24:48 -04:00
|
|
|
}
|
|
|
|
|
2019-11-19 01:13:14 -05:00
|
|
|
bool wofi_mod_control() {
|
|
|
|
return mod_ctrl;
|
|
|
|
}
|
|
|
|
|
2019-09-27 02:24:48 -04:00
|
|
|
void wofi_term_run(const char* cmd) {
|
|
|
|
if(terminal != NULL) {
|
|
|
|
execlp(terminal, terminal, "--", cmd, NULL);
|
|
|
|
}
|
|
|
|
size_t term_count = sizeof(terminals) / sizeof(char*);
|
|
|
|
for(size_t count = 0; count < term_count; ++count) {
|
|
|
|
execlp(terminals[count], terminals[count], "--", cmd, NULL);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "No terminal emulator found please set term in config or use --term\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-08-28 22:33:08 -04:00
|
|
|
static void select_item(GtkFlowBox* flow_box, gpointer data) {
|
2019-08-17 21:34:56 -04:00
|
|
|
(void) data;
|
|
|
|
if(previous_selection != NULL) {
|
|
|
|
gtk_widget_set_name(previous_selection, "unselected");
|
|
|
|
}
|
2019-08-28 22:33:08 -04:00
|
|
|
GList* selected_children = gtk_flow_box_get_selected_children(flow_box);
|
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(selected_children->data));
|
|
|
|
g_list_free(selected_children);
|
2019-08-28 02:15:18 -04:00
|
|
|
gtk_widget_set_name(box, "selected");
|
|
|
|
previous_selection = box;
|
2019-08-17 21:34:56 -04:00
|
|
|
}
|
|
|
|
|
2019-10-13 15:42:05 -04:00
|
|
|
static GtkWidget* get_first_child(GtkContainer* container) {
|
|
|
|
GList* children = gtk_container_get_children(container);
|
|
|
|
GList* list = children;
|
|
|
|
GtkWidget* min_child = NULL;
|
|
|
|
int64_t x = INT64_MAX;
|
|
|
|
int64_t y = INT64_MAX;
|
2019-11-04 16:55:35 -05:00
|
|
|
for(; list != NULL; list = list->next) {
|
2019-10-13 15:42:05 -04:00
|
|
|
GtkWidget* child = list->data;
|
|
|
|
GtkAllocation alloc;
|
|
|
|
gtk_widget_get_allocation(child, &alloc);
|
2019-11-04 20:46:39 -05:00
|
|
|
if(alloc.x <= x && alloc.y <= y && alloc.x != -1 && alloc.y != -1 && alloc.width != 1 && alloc.height != 1 && gtk_widget_get_child_visible(child)) {
|
2019-10-13 15:42:05 -04:00
|
|
|
x = alloc.x;
|
|
|
|
y = alloc.y;
|
|
|
|
min_child = child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free(children);
|
|
|
|
return min_child;
|
|
|
|
}
|
|
|
|
|
2019-08-17 21:19:32 -04:00
|
|
|
static void activate_search(GtkEntry* entry, gpointer data) {
|
2019-08-19 20:34:12 -04:00
|
|
|
(void) data;
|
2019-11-04 20:46:39 -05:00
|
|
|
GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box));
|
|
|
|
if(exec_search || child == NULL) {
|
2019-11-16 17:52:20 -05:00
|
|
|
execute_action(mode, gtk_entry_get_text(entry));
|
2019-08-19 20:34:12 -04:00
|
|
|
} else {
|
2019-10-13 15:42:05 -04:00
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(child));
|
2019-11-13 04:17:45 -05:00
|
|
|
bool primary_action = GTK_IS_EXPANDER(box);
|
|
|
|
if(primary_action) {
|
|
|
|
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
|
|
|
|
}
|
2019-11-16 17:52:20 -05:00
|
|
|
execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
|
2019-08-19 20:34:12 -04:00
|
|
|
}
|
2019-08-17 21:19:32 -04:00
|
|
|
}
|
|
|
|
|
2019-08-28 22:33:08 -04:00
|
|
|
static gboolean do_filter(GtkFlowBoxChild* row, gpointer data) {
|
2019-08-17 21:19:32 -04:00
|
|
|
(void) data;
|
2019-08-28 02:15:18 -04:00
|
|
|
GtkWidget* box = gtk_bin_get_child(GTK_BIN(row));
|
2019-11-13 04:17:45 -05:00
|
|
|
if(GTK_IS_EXPANDER(box)) {
|
|
|
|
box = gtk_expander_get_label_widget(GTK_EXPANDER(box));
|
|
|
|
}
|
2019-08-28 02:15:18 -04:00
|
|
|
const gchar* text = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "filter");
|
2019-08-17 21:19:32 -04:00
|
|
|
if(filter == NULL || strcmp(filter, "") == 0) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-08-29 00:15:29 -04:00
|
|
|
if(text == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-11-25 17:56:46 -05:00
|
|
|
if(insensitive) {
|
|
|
|
return strcasestr(text, filter) != NULL;
|
|
|
|
} else {
|
|
|
|
return strstr(text, filter) != NULL;
|
|
|
|
}
|
2019-11-21 04:01:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint do_sort(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer data) {
|
|
|
|
(void) data;
|
|
|
|
GtkWidget* box1 = gtk_bin_get_child(GTK_BIN(child1));
|
|
|
|
GtkWidget* box2 = gtk_bin_get_child(GTK_BIN(child2));
|
|
|
|
if(GTK_IS_EXPANDER(box1)) {
|
|
|
|
box1 = gtk_expander_get_label_widget(GTK_EXPANDER(box1));
|
|
|
|
}
|
|
|
|
if(GTK_IS_EXPANDER(box2)) {
|
|
|
|
box2 = gtk_expander_get_label_widget(GTK_EXPANDER(box2));
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar* text1 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "filter");
|
|
|
|
const gchar* text2 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "filter");
|
|
|
|
if(filter == NULL || strcmp(filter, "") == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(text1 == NULL || text2 == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
size_t dist1 = utils_distance(text1, filter);
|
|
|
|
size_t dist2 = utils_distance(text2, filter);
|
|
|
|
if(dist1 < dist2) {
|
|
|
|
return -1;
|
|
|
|
} else if(dist1 > dist2) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2019-08-17 21:19:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 21:23:45 -04:00
|
|
|
static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
2019-08-17 21:19:32 -04:00
|
|
|
(void) widget;
|
|
|
|
(void) data;
|
2019-09-27 02:24:48 -04:00
|
|
|
switch(event->key.keyval) {
|
2019-08-18 21:23:45 -04:00
|
|
|
case GDK_KEY_Escape:
|
2019-08-17 21:19:32 -04:00
|
|
|
exit(0);
|
2019-08-18 21:23:45 -04:00
|
|
|
break;
|
|
|
|
case GDK_KEY_Up:
|
|
|
|
case GDK_KEY_Left:
|
2019-10-13 01:24:35 -04:00
|
|
|
break;
|
2019-08-18 21:23:45 -04:00
|
|
|
case GDK_KEY_Return:
|
2019-11-19 01:16:06 -05:00
|
|
|
mod_shift = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
|
2019-11-19 01:13:14 -05:00
|
|
|
mod_ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
|
2019-11-19 01:16:06 -05:00
|
|
|
if(mod_shift) {
|
2019-09-27 02:24:48 -04:00
|
|
|
event->key.state &= ~GDK_SHIFT_MASK;
|
|
|
|
}
|
2019-11-19 01:13:14 -05:00
|
|
|
if(mod_ctrl) {
|
|
|
|
event->key.state &= ~GDK_CONTROL_MASK;
|
|
|
|
}
|
2019-09-19 03:45:57 -04:00
|
|
|
if(gtk_widget_has_focus(scroll)) {
|
|
|
|
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
|
|
|
|
}
|
2019-08-18 21:23:45 -04:00
|
|
|
break;
|
2019-10-07 05:50:26 -04:00
|
|
|
case GDK_KEY_Tab:
|
2019-08-28 22:33:08 -04:00
|
|
|
case GDK_KEY_Down:
|
2019-10-13 01:24:35 -04:00
|
|
|
case GDK_KEY_Right:
|
|
|
|
if(event->key.keyval == GDK_KEY_Down && outer_orientation == GTK_ORIENTATION_HORIZONTAL) {
|
|
|
|
return FALSE;
|
|
|
|
} else if(event->key.keyval == GDK_KEY_Right && outer_orientation == GTK_ORIENTATION_VERTICAL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-09-19 03:45:57 -04:00
|
|
|
if(gtk_widget_has_focus(entry) || gtk_widget_has_focus(scroll)) {
|
2019-10-13 15:42:05 -04:00
|
|
|
GtkWidget* child = get_first_child(GTK_CONTAINER(inner_box));
|
|
|
|
gtk_widget_grab_focus(child);
|
|
|
|
gtk_flow_box_select_child(GTK_FLOW_BOX(inner_box), GTK_FLOW_BOX_CHILD(child));
|
2019-08-29 00:55:30 -04:00
|
|
|
return TRUE;
|
2019-08-28 22:33:08 -04:00
|
|
|
}
|
|
|
|
break;
|
2019-10-01 00:38:56 -04:00
|
|
|
case GDK_KEY_Shift_L:case GDK_KEY_Shift_R:
|
2019-11-19 01:13:14 -05:00
|
|
|
case GDK_KEY_Control_L:case GDK_KEY_Control_R:
|
2019-10-01 00:38:56 -04:00
|
|
|
break;
|
2019-08-18 21:23:45 -04:00
|
|
|
default:
|
|
|
|
if(!gtk_widget_has_focus(entry)) {
|
2019-08-18 21:31:34 -04:00
|
|
|
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
|
2019-08-18 21:23:45 -04:00
|
|
|
}
|
|
|
|
break;
|
2019-08-17 21:19:32 -04:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-13 03:25:25 -04:00
|
|
|
static void* get_plugin_proc(const char* prefix, const char* suffix) {
|
2019-11-04 16:25:44 -05:00
|
|
|
char* proc_name = utils_concat(3, "wofi_", prefix, suffix);
|
2019-09-13 03:25:25 -04:00
|
|
|
void* proc = dlsym(RTLD_DEFAULT, proc_name);
|
|
|
|
free(proc_name);
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
2019-11-04 23:56:40 -05:00
|
|
|
static void add_mode(char* mode) {
|
2019-09-13 03:25:25 -04:00
|
|
|
char* dso = strstr(mode, ".so");
|
2019-11-04 23:56:40 -05:00
|
|
|
struct mode* mode_ptr = calloc(1, sizeof(struct mode));
|
|
|
|
map_put_void(modes, mode, mode_ptr);
|
2019-09-13 03:25:25 -04:00
|
|
|
|
|
|
|
void (*init)();
|
|
|
|
if(dso == NULL) {
|
|
|
|
init = get_plugin_proc(mode, "_init");
|
2019-11-04 23:56:40 -05:00
|
|
|
mode_ptr->mode_exec = get_plugin_proc(mode, "_exec");
|
2019-09-13 03:25:25 -04:00
|
|
|
} else {
|
|
|
|
char* plugins_dir = utils_concat(2, config_dir, "/plugins/");
|
|
|
|
char* full_name = utils_concat(2, plugins_dir, mode);
|
2019-11-04 16:29:53 -05:00
|
|
|
void* plugin = dlopen(full_name, RTLD_LAZY | RTLD_LOCAL);
|
2019-09-13 03:25:25 -04:00
|
|
|
free(full_name);
|
|
|
|
free(plugins_dir);
|
|
|
|
init = dlsym(plugin, "init");
|
2019-11-04 23:56:40 -05:00
|
|
|
mode_ptr->mode_exec = dlsym(plugin, "exec");
|
2019-09-13 03:25:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(init != NULL) {
|
|
|
|
init();
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "I would love to show %s but Idk what it is\n", mode);
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-11-04 23:56:40 -05:00
|
|
|
}
|
2019-09-13 03:25:25 -04:00
|
|
|
|
2019-11-04 23:56:40 -05:00
|
|
|
static void* start_thread(void* data) {
|
2019-11-05 01:41:53 -05:00
|
|
|
(void) data;
|
|
|
|
if(strchr(mode, ',') != NULL) {
|
2019-11-04 23:56:40 -05:00
|
|
|
char* save_ptr;
|
2019-11-05 01:41:53 -05:00
|
|
|
char* str = strtok_r(mode, ",", &save_ptr);
|
2019-11-04 23:56:40 -05:00
|
|
|
do {
|
2019-11-05 01:41:53 -05:00
|
|
|
add_mode(str);
|
|
|
|
} while((str = strtok_r(NULL, ",", &save_ptr)) != NULL);
|
2019-11-04 23:56:40 -05:00
|
|
|
} else {
|
2019-11-05 01:41:53 -05:00
|
|
|
add_mode(mode);
|
2019-11-04 23:56:40 -05:00
|
|
|
}
|
2019-09-13 03:25:25 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-17 21:19:32 -04:00
|
|
|
void wofi_init(struct map* config) {
|
|
|
|
width = strtol(config_get(config, "width", "1000"), NULL, 10);
|
|
|
|
height = strtol(config_get(config, "height", "400"), NULL, 10);
|
|
|
|
x = strtol(config_get(config, "x", "-1"), NULL, 10);
|
|
|
|
y = strtol(config_get(config, "y", "-1"), NULL, 10);
|
2019-08-17 22:22:09 -04:00
|
|
|
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
|
2019-11-05 01:41:53 -05:00
|
|
|
mode = map_get(config, "mode");
|
2019-09-13 03:39:41 -04:00
|
|
|
uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal");
|
2019-10-13 01:24:35 -04:00
|
|
|
outer_orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "horizontal", "vertical");
|
2019-08-28 22:33:08 -04:00
|
|
|
uint8_t halign = config_get_mnemonic(config, "halign", "fill", 4, "fill", "start", "end", "center");
|
2019-10-13 01:24:35 -04:00
|
|
|
char* default_valign = "start";
|
|
|
|
if(outer_orientation == GTK_ORIENTATION_HORIZONTAL) {
|
|
|
|
default_valign = "center";
|
|
|
|
}
|
|
|
|
uint8_t valign = config_get_mnemonic(config, "valign", default_valign, 4, "fill", "start", "end", "center");
|
2019-08-17 21:19:32 -04:00
|
|
|
char* prompt = config_get(config, "prompt", mode);
|
2019-08-27 00:19:59 -04:00
|
|
|
filter_rate = strtol(config_get(config, "filter_rate", "100"), NULL, 10);
|
|
|
|
filter_time = utils_get_time_millis();
|
2019-08-28 02:15:18 -04:00
|
|
|
allow_images = strcmp(config_get(config, "allow_images", "false"), "true") == 0;
|
2019-08-28 03:58:45 -04:00
|
|
|
allow_markup = strcmp(config_get(config, "allow_markup", "false"), "true") == 0;
|
2019-08-28 20:36:20 -04:00
|
|
|
image_size = strtol(config_get(config, "image_size", "32"), NULL, 10);
|
2019-08-28 23:14:38 -04:00
|
|
|
cache_file = map_get(config, "cache_file");
|
2019-09-13 03:25:25 -04:00
|
|
|
config_dir = map_get(config, "config_dir");
|
2019-09-27 02:24:48 -04:00
|
|
|
terminal = map_get(config, "term");
|
2019-10-23 00:19:57 -04:00
|
|
|
char* password_char = map_get(config, "password_char");
|
2019-11-04 20:46:39 -05:00
|
|
|
exec_search = strcmp(config_get(config, "exec_search", "false"), "true") == 0;
|
2019-11-18 16:42:40 -05:00
|
|
|
bool hide_scroll = strcmp(config_get(config, "hide_scroll", "false"), "true") == 0;
|
2019-11-21 04:01:27 -05:00
|
|
|
matching = config_get_mnemonic(config, "matching", "contains", 2, "contains", "fuzzy");
|
2019-11-25 17:56:46 -05:00
|
|
|
insensitive = strcmp(config_get(config, "insensitive", "false"), "true") == 0;
|
2019-11-04 23:56:40 -05:00
|
|
|
modes = map_init_void();
|
2019-08-17 21:19:32 -04:00
|
|
|
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_widget_realize(window);
|
|
|
|
gtk_widget_set_name(window, "window");
|
2019-08-17 22:22:09 -04:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
|
|
|
|
gtk_window_resize(GTK_WINDOW(window), width, height);
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
|
|
|
|
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
|
|
|
if(!normal_window) {
|
|
|
|
GdkDisplay* disp = gdk_display_get_default();
|
|
|
|
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
|
|
|
|
struct wl_registry* registry = wl_display_get_registry(wl);
|
|
|
|
struct wl_registry_listener listener = {
|
|
|
|
.global = add_interface,
|
|
|
|
.global_remove = nop
|
|
|
|
};
|
|
|
|
wl_registry_add_listener(registry, &listener, NULL);
|
|
|
|
wl_display_roundtrip(wl);
|
|
|
|
GdkWindow* gdk_win = gtk_widget_get_window(window);
|
|
|
|
gdk_wayland_window_set_use_custom_surface(gdk_win);
|
|
|
|
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
|
|
|
|
struct zwlr_layer_surface_v1* surface = zwlr_layer_shell_v1_get_layer_surface(shell, wl_surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "wofi");
|
|
|
|
struct zwlr_layer_surface_v1_listener* surface_listener = malloc(sizeof(struct zwlr_layer_surface_v1_listener));
|
|
|
|
surface_listener->configure = config_surface;
|
|
|
|
surface_listener->closed = nop;
|
|
|
|
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
|
|
|
|
wl_surface_commit(wl_surface);
|
|
|
|
wl_display_roundtrip(wl);
|
|
|
|
}
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-10-13 01:24:35 -04:00
|
|
|
outer_box = gtk_box_new(outer_orientation, 0);
|
2019-08-19 20:34:12 -04:00
|
|
|
gtk_widget_set_name(outer_box, "outer-box");
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), outer_box);
|
|
|
|
entry = gtk_search_entry_new();
|
2019-08-17 21:19:32 -04:00
|
|
|
gtk_widget_set_name(entry, "input");
|
|
|
|
gtk_entry_set_placeholder_text(GTK_ENTRY(entry), prompt);
|
2019-08-19 20:34:12 -04:00
|
|
|
gtk_container_add(GTK_CONTAINER(outer_box), entry);
|
2019-10-23 00:19:57 -04:00
|
|
|
if(password_char != NULL) {
|
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
|
|
|
|
gtk_entry_set_invisible_char(GTK_ENTRY(entry), password_char[0]);
|
|
|
|
}
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-08-19 20:34:12 -04:00
|
|
|
scroll = gtk_scrolled_window_new(NULL, NULL);
|
2019-08-17 21:19:32 -04:00
|
|
|
gtk_widget_set_name(scroll, "scroll");
|
2019-08-19 20:34:12 -04:00
|
|
|
gtk_container_add(GTK_CONTAINER(outer_box), scroll);
|
2019-08-17 21:19:32 -04:00
|
|
|
gtk_widget_set_size_request(scroll, width, height);
|
2019-11-18 16:42:40 -05:00
|
|
|
if(hide_scroll) {
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_EXTERNAL, GTK_POLICY_EXTERNAL);
|
|
|
|
}
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-08-28 22:33:08 -04:00
|
|
|
inner_box = gtk_flow_box_new();
|
|
|
|
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(inner_box), 1);
|
|
|
|
gtk_orientable_set_orientation(GTK_ORIENTABLE(inner_box), orientation);
|
|
|
|
gtk_widget_set_halign(inner_box, halign);
|
|
|
|
gtk_widget_set_valign(inner_box, valign);
|
|
|
|
|
2019-08-17 21:19:32 -04:00
|
|
|
gtk_widget_set_name(inner_box, "inner-box");
|
2019-08-28 22:33:08 -04:00
|
|
|
gtk_flow_box_set_activate_on_single_click(GTK_FLOW_BOX(inner_box), FALSE);
|
2019-10-13 02:56:27 -04:00
|
|
|
|
|
|
|
GtkWidget* wrapper_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_box_set_homogeneous(GTK_BOX(wrapper_box), TRUE);
|
|
|
|
gtk_container_add(GTK_CONTAINER(wrapper_box), inner_box);
|
|
|
|
gtk_container_add(GTK_CONTAINER(scroll), wrapper_box);
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-11-21 04:01:27 -05:00
|
|
|
switch(matching) {
|
|
|
|
case MATCHING_MODE_CONTAINS:
|
|
|
|
gtk_flow_box_set_filter_func(GTK_FLOW_BOX(inner_box), do_filter, NULL, NULL);
|
|
|
|
break;
|
|
|
|
case MATCHING_MODE_FUZZY:
|
|
|
|
gtk_flow_box_set_sort_func(GTK_FLOW_BOX(inner_box), do_sort, NULL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-08-27 00:19:59 -04:00
|
|
|
g_signal_connect(entry, "changed", G_CALLBACK(get_input), NULL);
|
|
|
|
g_signal_connect(entry, "search-changed", G_CALLBACK(get_search), NULL);
|
2019-08-28 22:33:08 -04:00
|
|
|
g_signal_connect(inner_box, "child-activated", G_CALLBACK(activate_item), NULL);
|
|
|
|
g_signal_connect(inner_box, "selected-children-changed", G_CALLBACK(select_item), NULL);
|
2019-08-19 20:34:12 -04:00
|
|
|
g_signal_connect(entry, "activate", G_CALLBACK(activate_search), NULL);
|
|
|
|
g_signal_connect(window, "key-press-event", G_CALLBACK(key_press), NULL);
|
2019-08-17 21:19:32 -04:00
|
|
|
|
2019-08-18 21:06:13 -04:00
|
|
|
pthread_t thread;
|
2019-11-05 01:41:53 -05:00
|
|
|
pthread_create(&thread, NULL, start_thread, NULL);
|
2019-09-19 02:35:51 -04:00
|
|
|
gtk_widget_grab_focus(scroll);
|
2019-08-18 01:00:23 -04:00
|
|
|
gtk_window_set_title(GTK_WINDOW(window), prompt);
|
2019-08-17 22:22:09 -04:00
|
|
|
gtk_widget_show_all(window);
|
2019-08-17 21:19:32 -04:00
|
|
|
}
|