gdk_threads_add_timeout() is now used instead of g_timeout_add()
This commit is contained in:
parent
b88c6727ea
commit
a55c0421b2
@ -42,4 +42,6 @@
|
|||||||
#include <wlr-layer-shell-unstable-v1-client-protocol.h>
|
#include <wlr-layer-shell-unstable-v1-client-protocol.h>
|
||||||
|
|
||||||
void wofi_init(struct map* config);
|
void wofi_init(struct map* config);
|
||||||
|
|
||||||
|
void wofi_load_css(bool nyan);
|
||||||
#endif
|
#endif
|
||||||
|
18
src/main.c
18
src/main.c
@ -27,12 +27,16 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static const char* nyan_colors[] = {"#FF0000", "#FFA500", "#FFFF00", "#00FF00", "#0000FF", "#FF00FF"};
|
||||||
|
static size_t nyan_color_l = sizeof(nyan_colors) / sizeof(char*);
|
||||||
|
|
||||||
static char* CONFIG_LOCATION;
|
static char* CONFIG_LOCATION;
|
||||||
static char* COLORS_LOCATION;
|
static char* COLORS_LOCATION;
|
||||||
static struct map* config;
|
static struct map* config;
|
||||||
static char* config_path;
|
static char* config_path;
|
||||||
static char* stylesheet;
|
static char* stylesheet;
|
||||||
static char* color_path;
|
static char* color_path;
|
||||||
|
static uint8_t nyan_shift = 0;
|
||||||
|
|
||||||
struct option_node {
|
struct option_node {
|
||||||
char* option;
|
char* option;
|
||||||
@ -86,7 +90,7 @@ static void print_usage(char** argv) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_css(void) {
|
void wofi_load_css(bool nyan) {
|
||||||
if(access(stylesheet, R_OK) == 0) {
|
if(access(stylesheet, R_OK) == 0) {
|
||||||
FILE* file = fopen(stylesheet, "r");
|
FILE* file = fopen(stylesheet, "r");
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
@ -103,6 +107,15 @@ static void load_css(void) {
|
|||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
wl_list_init(&lines);
|
wl_list_init(&lines);
|
||||||
|
if(nyan) {
|
||||||
|
for(ssize_t count = nyan_shift; count < 32 + nyan_shift; ++count) {
|
||||||
|
size_t i = count % nyan_color_l;
|
||||||
|
struct node* entry = malloc(sizeof(struct node));
|
||||||
|
entry->line = strdup(nyan_colors[i]);
|
||||||
|
wl_list_insert(&lines, &entry->link);
|
||||||
|
}
|
||||||
|
nyan_shift = (nyan_shift + 1) % nyan_color_l;
|
||||||
|
} else {
|
||||||
if(access(color_path, R_OK) == 0) {
|
if(access(color_path, R_OK) == 0) {
|
||||||
file = fopen(color_path, "r");
|
file = fopen(color_path, "r");
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
@ -118,6 +131,7 @@ static void load_css(void) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t count = wl_list_length(&lines) - 1;
|
ssize_t count = wl_list_length(&lines) - 1;
|
||||||
if(count > 99) {
|
if(count > 99) {
|
||||||
@ -706,7 +720,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
load_css();
|
wofi_load_css(false);
|
||||||
|
|
||||||
wofi_init(config);
|
wofi_init(config);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
55
src/wofi.c
55
src/wofi.c
@ -72,6 +72,8 @@ static int64_t max_height = 0;
|
|||||||
static uint64_t lines;
|
static uint64_t lines;
|
||||||
static int8_t line_wrap;
|
static int8_t line_wrap;
|
||||||
static int64_t ix, iy;
|
static int64_t ix, iy;
|
||||||
|
static uint8_t konami_cycle;
|
||||||
|
static bool is_konami = false;
|
||||||
|
|
||||||
static char* key_up, *key_down, *key_left, *key_right, *key_forward, *key_backward, *key_submit, *key_exit;
|
static char* key_up, *key_down, *key_left, *key_right, *key_forward, *key_backward, *key_submit, *key_exit;
|
||||||
static char* mod_up, *mod_down, *mod_left, *mod_right, *mod_forward, *mod_backward, *mod_exit;
|
static char* mod_up, *mod_down, *mod_left, *mod_right, *mod_forward, *mod_backward, *mod_exit;
|
||||||
@ -1025,12 +1027,63 @@ static bool has_mod(guint state) {
|
|||||||
return (state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK || (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
|
return (state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK || (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean do_nyan(gpointer data) {
|
||||||
|
(void) data;
|
||||||
|
wofi_load_css(true);
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static guint get_konami_key(uint8_t cycle) {
|
||||||
|
switch(cycle) {
|
||||||
|
case 0:
|
||||||
|
return GDK_KEY_Up;
|
||||||
|
case 1:
|
||||||
|
return GDK_KEY_Up;
|
||||||
|
case 2:
|
||||||
|
return GDK_KEY_Down;
|
||||||
|
case 3:
|
||||||
|
return GDK_KEY_Down;
|
||||||
|
case 4:
|
||||||
|
return GDK_KEY_Left;
|
||||||
|
case 5:
|
||||||
|
return GDK_KEY_Right;
|
||||||
|
case 6:
|
||||||
|
return GDK_KEY_Left;
|
||||||
|
case 7:
|
||||||
|
return GDK_KEY_Right;
|
||||||
|
case 8:
|
||||||
|
return GDK_KEY_b;
|
||||||
|
case 9:
|
||||||
|
return GDK_KEY_a;
|
||||||
|
case 10:
|
||||||
|
return GDK_KEY_Return;
|
||||||
|
default:
|
||||||
|
return GDK_KEY_VoidSymbol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
||||||
(void) widget;
|
(void) widget;
|
||||||
(void) data;
|
(void) data;
|
||||||
gchar* name = gdk_keyval_name(event->key.keyval);
|
gchar* name = gdk_keyval_name(event->key.keyval);
|
||||||
bool printable = strlen(name) == 1 && isprint(name[0]) && !has_mod(event->key.state);
|
bool printable = strlen(name) == 1 && isprint(name[0]) && !has_mod(event->key.state);
|
||||||
|
|
||||||
|
guint konami_key = get_konami_key(konami_cycle);
|
||||||
|
if(event->key.keyval == konami_key) {
|
||||||
|
if(konami_cycle == 10) {
|
||||||
|
konami_cycle = 0;
|
||||||
|
if(!is_konami) {
|
||||||
|
is_konami = true;
|
||||||
|
gdk_threads_add_timeout(500, do_nyan, NULL);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
++konami_cycle;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
konami_cycle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if(gtk_widget_has_focus(entry) && printable) {
|
if(gtk_widget_has_focus(entry) && printable) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1418,7 +1471,7 @@ void wofi_init(struct map* _config) {
|
|||||||
g_signal_connect(window, "focus-in-event", G_CALLBACK(focus), NULL);
|
g_signal_connect(window, "focus-in-event", G_CALLBACK(focus), NULL);
|
||||||
g_signal_connect(window, "focus-out-event", G_CALLBACK(focus), NULL);
|
g_signal_connect(window, "focus-out-event", G_CALLBACK(focus), NULL);
|
||||||
|
|
||||||
g_timeout_add(filter_rate, do_search, NULL);
|
gdk_threads_add_timeout(filter_rate, do_search, NULL);
|
||||||
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, NULL, start_thread, mode);
|
pthread_create(&thread, NULL, start_thread, mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user