From ece810805d8411526a7c579d2eca7fd34eb5e0d3 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 27 Jul 2023 00:39:57 +0200 Subject: [PATCH] Change some variable names & cleanup --- libs/draw.c | 42 +++++++++++++----------- libs/img.c | 2 +- libs/wl/init.c | 2 +- libs/wl/wayland.c | 81 ++++++++++++++++++++++------------------------- libs/wl/wayland.h | 3 +- spmenu.c | 2 ++ 6 files changed, 67 insertions(+), 65 deletions(-) diff --git a/libs/draw.c b/libs/draw.c index 05a5cfd..f280152 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -597,13 +597,15 @@ int drawcaps(int x, int y, int w) { } void drawmenu(void) { + if (sp.isdrawing) { + while (sp.isdrawing != 0) { + ; + } + } + + sp.isdrawing = 1; #if USEWAYLAND if (protocol) { - drawmenu_layer(); - -#if USEIMAGE - drawimage(); -#endif if (listfile) { readstdin(); @@ -616,15 +618,16 @@ void drawmenu(void) { currentitem = nextitem; } } - - drawmenu_layer(); } } - wl_surface_set_buffer_scale(state.surface, 1); - wl_surface_attach(state.surface, state.buffer, 0, 0); - wl_surface_damage(state.surface, 0, 0, state.width, state.height); - wl_surface_commit(state.surface); + drawmenu_layer(); + +#if USEIMAGE + drawimage(); +#endif + + commit_drawable(&state); } else { #endif #if USEX @@ -641,11 +644,19 @@ void drawmenu(void) { } } } + drawmenu_layer(); + +#if USEIMAGE + drawimage(); +#endif + draw_map(draw, win, 0, 0, sp.mw, sp.mh); #endif #if USEWAYLAND } #endif + + sp.isdrawing = 0; } void drawmenu_layer(void) { @@ -739,11 +750,4 @@ void drawmenu_layer(void) { w ); } - -#if USEX -#if USEIMAGE - drawimage(); -#endif - draw_map(draw, win, 0, 0, sp.mw, sp.mh); -#endif - } +} diff --git a/libs/img.c b/libs/img.c index 2cefa1f..a3a5d52 100644 --- a/libs/img.c +++ b/libs/img.c @@ -366,7 +366,7 @@ void resizetoimageheight_x11(int imageheight) { jumptoindex(i); } - drawmenu_layer(); + drawmenu(); } #endif diff --git a/libs/wl/init.c b/libs/wl/init.c index 8aee4a9..a34ade5 100644 --- a/libs/wl/init.c +++ b/libs/wl/init.c @@ -58,7 +58,7 @@ void handle_wl(void) { roundtrip(&state); match(); - draw_sf(&state); + create_drawable(&state); while (wl_display_dispatch(state.display) != -1) { } diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 4540722..972abc4 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -38,36 +38,36 @@ struct wl_buffer *create_buffer(struct state *state) { * PLEASE submit a patch if you have an improvement. */ int is_correct_modifier(struct state *state, char *modifier) { - int altPress = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_ALT, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); - int shiftPress = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); - int ctrlPress = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); - int logoPress = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); + int alt_pressed = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_ALT, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); + int shift_pressed = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); + int ctrl_pressed = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); + int logo_pressed = xkb_state_mod_name_is_active(state->xkb_state, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); - if (!strcmp(modifier, WL_CtrlShift) && shiftPress && ctrlPress) { + if (!strcmp(modifier, WL_CtrlShift) && shift_pressed && ctrl_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlShiftSuper) && shiftPress && ctrlPress && logoPress) { + } else if (!strcmp(modifier, WL_CtrlShiftSuper) && shift_pressed && ctrl_pressed && logo_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlSuper) && ctrlPress && logoPress) { + } else if (!strcmp(modifier, WL_CtrlSuper) && ctrl_pressed && logo_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlAlt) && altPress && ctrlPress) { + } else if (!strcmp(modifier, WL_CtrlAlt) && alt_pressed && ctrl_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlAltShift) && ctrlPress && altPress && shiftPress) { + } else if (!strcmp(modifier, WL_CtrlAltShift) && ctrl_pressed && alt_pressed && shift_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlAltShiftSuper) && ctrlPress && altPress && shiftPress && logoPress) { + } else if (!strcmp(modifier, WL_CtrlAltShiftSuper) && ctrl_pressed && alt_pressed && shift_pressed && logo_pressed) { return 0; - } else if (!strcmp(modifier, WL_CtrlAltSuper) && ctrlPress && altPress && logoPress) { + } else if (!strcmp(modifier, WL_CtrlAltSuper) && ctrl_pressed && alt_pressed && logo_pressed) { return 0; - } else if (!strcmp(modifier, WL_AltShift) && altPress && shiftPress) { + } else if (!strcmp(modifier, WL_AltShift) && alt_pressed && shift_pressed) { return 0; - } else if (!strcmp(modifier, WL_Shift) && shiftPress) { + } else if (!strcmp(modifier, WL_Shift) && shift_pressed) { return 0; - } else if (!strcmp(modifier, WL_Ctrl) && ctrlPress) { + } else if (!strcmp(modifier, WL_Ctrl) && ctrl_pressed) { return 0; - } else if (!strcmp(modifier, WL_Alt) && altPress) { + } else if (!strcmp(modifier, WL_Alt) && alt_pressed) { return 0; - } else if (!strcmp(modifier, WL_Super) && logoPress) { + } else if (!strcmp(modifier, WL_Super) && logo_pressed) { return 0; - } else if (!strcmp(modifier, WL_None) && !altPress && !shiftPress && !ctrlPress && !logoPress) { + } else if (!strcmp(modifier, WL_None) && !alt_pressed && !shift_pressed && !ctrl_pressed && !logo_pressed) { return 0; } @@ -288,18 +288,18 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { yp = 1; } - click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific + click = ClickWindow; // Clicking anywhere, we use this and override it if we clicked on something specific - // check click position and override the value of click - if (yp && ex < x + sp.promptw + powerlineprompt ? sp.plw : 0) { // prompt + // Check click position and override the value of click + if (yp && ex < x + sp.promptw + powerlineprompt ? sp.plw : 0) { click = ClickPrompt; - } else if (yp && (ex > sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsw) { // caps lock indicator + } else if (yp && (ex > sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsw) { click = ClickCaps; - } else if (yp && ex > sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator + } else if (yp && ex > sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { click = ClickMode; - } else if (yp && ex > sp.mw - modew - numberw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count + } else if (yp && ex > sp.mw - modew - numberw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { click = ClickNumber; - } else if (yp && !hideinput) { // input + } else if (yp && !hideinput) { w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; if ((lines <= 0 && ex >= 0 && ex <= x + w + sp.promptw + @@ -316,7 +316,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } #endif - // item click + // It's an item click if (lines > 0) { w = sp.mw - x; @@ -345,7 +345,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { #endif } } - } else if (matches) { // a single line, meaning it could be arrows too, so we check that here + } else if (matches) { // Single line x += sp.inputw; w = larroww; @@ -355,22 +355,20 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } } - // right arrow w = rarroww; x = sp.mw - w; + if (nextitem && ex >= x && ex <= x + w) { click = ClickRArrow; } } - // go through mouse button array and run function for (i = 0; i < LENGTH(wl_buttons); i++) { if (sp.ignoreglobalmouse) break; if ((click == wl_buttons[i].click || wl_buttons[i].click == ClickNone) && wl_buttons[i].func && wl_buttons[i].button == button) wl_buttons[i].func(&wl_buttons[i].arg); } - // go through mouse config array and run function for (i = 0; i < LENGTH(wl_cbuttons); i++) { if (sp.ignoreconfmouse) break; if ((click == wl_cbuttons[i].click || wl_cbuttons[i].click == ClickNone) && wl_cbuttons[i].func && wl_cbuttons[i].button == button) @@ -462,7 +460,7 @@ void zero() { // Nothing. } -void draw_sf(struct state *state) { +void create_drawable(struct state *state) { if (!allow_draw) { // No drawing if disabled return; } @@ -479,13 +477,7 @@ void draw_sf(struct state *state) { } draw_create_surface_wl(draw, state->data, state->width, state->height); - - drawmenu_layer(); - - wl_surface_set_buffer_scale(state->surface, 1); - wl_surface_attach(state->surface, state->buffer, 0, 0); - wl_surface_damage(state->surface, 0, 0, state->width, state->height); - wl_surface_commit(state->surface); + drawmenu(); } void global_handler(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { @@ -519,7 +511,14 @@ void surface_enter(void *data, struct wl_surface *surface, struct wl_output *wl_ state->output = wl_output_get_user_data(wl_output); match(); - draw_sf(state); + create_drawable(state); +} + +void commit_drawable(struct state *state) { + wl_surface_set_buffer_scale(state->surface, 1); + wl_surface_attach(state->surface, state->buffer, 0, 0); + wl_surface_damage(state->surface, 0, 0, state->width, state->height); + wl_surface_commit(state->surface); } int roundtrip(struct state *state) { @@ -577,7 +576,6 @@ void resizeclient_wl(struct state *state) { int mh = sp.mh; int ic = 0; - // walk through all items for (item = items; item && item->text; item++) ic++; @@ -611,10 +609,7 @@ void resizeclient_wl(struct state *state) { draw_create_surface_wl(draw, state->data, state->width, state->height); set_layer_size(state, state->width, state->height); - wl_surface_set_buffer_scale(state->surface, 1); - wl_surface_attach(state->surface, state->buffer, 0, 0); - wl_surface_damage(state->surface, 0, 0, state->width, state->height); - wl_surface_commit(state->surface); + commit_drawable(state); } /* It is advised you call this function right before calling init_disp() diff --git a/libs/wl/wayland.h b/libs/wl/wayland.h index 51746bf..01d71a9 100644 --- a/libs/wl/wayland.h +++ b/libs/wl/wayland.h @@ -124,7 +124,8 @@ static void output_geometry(void *data, struct wl_output *wl_output, int32_t x, static void output_mode(void *data, struct wl_output *wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh); static void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height); static void layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface); -static void draw_sf(struct state *state); +static void create_drawable(struct state *state); +static void commit_drawable(struct state *state); static void global_handler(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); static void seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps); static void surface_enter(void *data, struct wl_surface *surface, struct wl_output *wl_output); diff --git a/spmenu.c b/spmenu.c index 81eaff4..ed580f8 100644 --- a/spmenu.c +++ b/spmenu.c @@ -131,6 +131,7 @@ struct sp { int mode; // current mode int allowkeys; // interpret a keypress as an insertion? int capslockstate; // caps lock state + int isdrawing; int inputw; // input width int promptw; // prompt width @@ -609,6 +610,7 @@ void handle(void) { set_mode(); init_appearance(); // init colorschemes by reading arrays + setupdisplay_x11(); // set up display and create window eventloop_x11(); // function is a loop which checks X11 events and calls other functions accordingly #endif