diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-15 16:35:36 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-15 16:35:36 +0200 |
| commit | 893e4ab58fce2918480501f999313000b6de6249 (patch) | |
| tree | bd3d588210ef2aa56434fbf94adfc6f333311b84 /widgets.c | |
| parent | 91fe87974e8c0d02b230fb1218905920154f5af5 (diff) | |
| download | glitch-893e4ab58fce2918480501f999313000b6de6249.tar.gz | |
Add tiling and floating mode
Diffstat (limited to 'widgets.c')
| -rw-r--r-- | widgets.c | 53 |
1 files changed, 51 insertions, 2 deletions
@@ -44,13 +44,20 @@ void widget_mic_indicator(void) { XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)desktop_buf, strlen(desktop_buf), &desktop_extents); int desktop_size = (wm.font->height > desktop_extents.width ? wm.font->height : desktop_extents.width) + padding * 2; + // Layout indicator size + LayoutMode mode = wm.layout_modes[wm.current_desktop]; + const char *layout_buf = (mode == LAYOUT_TILING) ? "T" : "F"; + XGlyphInfo layout_extents; + XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)layout_buf, strlen(layout_buf), &layout_extents); + int layout_size_w = (wm.font->height > layout_extents.width ? wm.font->height : layout_extents.width) + padding * 2; + const char *buf = "MIC"; XGlyphInfo extents; XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)buf, strlen(buf), &extents); int size_w = extents.width + padding * 4; int size_h = desktop_size; - int x = screen_width - desktop_size - size_w - 20; + int x = screen_width - desktop_size - layout_size_w - size_w - 20; int y = 10; XftColor *bg = wm.mic_muted ? &wm.xft_mic_muted_bg : &wm.xft_mic_active_bg; @@ -66,6 +73,40 @@ void widget_mic_indicator(void) { XftDrawStringUtf8(wm.xft_draw, fg, wm.font, text_x, text_y, (FcChar8 *)buf, strlen(buf)); } +void widget_layout_indicator(void) { + int screen_width = DisplayWidth(wm.dpy, wm.screen); + int padding = 3; + + // Desktop indicator size + char desktop_buf[8]; + snprintf(desktop_buf, sizeof(desktop_buf), "%u", wm.current_desktop); + XGlyphInfo desktop_extents; + XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)desktop_buf, strlen(desktop_buf), &desktop_extents); + int desktop_size = (wm.font->height > desktop_extents.width ? wm.font->height : desktop_extents.width) + padding * 2; + + LayoutMode mode = wm.layout_modes[wm.current_desktop]; + const char *buf = (mode == LAYOUT_TILING) ? "T" : "F"; + XGlyphInfo extents; + XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)buf, strlen(buf), &extents); + + int size_w = (wm.font->height > extents.width ? wm.font->height : extents.width) + padding * 2; + int size_h = desktop_size; + int x = screen_width - desktop_size - size_w - 15; + int y = 10; + + XftColor *bg = (mode == LAYOUT_TILING) ? &wm.xft_layout_tile_bg : &wm.xft_layout_float_bg; + XftColor *fg = (mode == LAYOUT_TILING) ? &wm.xft_layout_tile_fg : &wm.xft_layout_float_fg; + + // Draw the background. + XftDrawRect(wm.xft_draw, bg, x, y, size_w, size_h); + + // Center the text. + int text_x = x + (size_w - extents.width) / 2 + extents.x; + int text_y = y + (size_h - wm.font->ascent - wm.font->descent) / 2 + wm.font->ascent; + + XftDrawStringUtf8(wm.xft_draw, fg, wm.font, text_x, text_y, (FcChar8 *)buf, strlen(buf)); +} + void widget_datetime(void) { int screen_width = DisplayWidth(wm.dpy, wm.screen); int padding = 3; @@ -77,13 +118,20 @@ void widget_datetime(void) { XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)desktop_buf, strlen(desktop_buf), &desktop_extents); int desktop_size = (wm.font->height > desktop_extents.width ? wm.font->height : desktop_extents.width) + padding * 2; + // Layout indicator size + LayoutMode mode = wm.layout_modes[wm.current_desktop]; + const char *layout_buf = (mode == LAYOUT_TILING) ? "T" : "F"; + XGlyphInfo layout_extents; + XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)layout_buf, strlen(layout_buf), &layout_extents); + int layout_size_w = (wm.font->height > layout_extents.width ? wm.font->height : layout_extents.width) + padding * 2; + // Mic indicator size const char *mic_buf = "MIC"; XGlyphInfo mic_extents; XftTextExtentsUtf8(wm.dpy, wm.font, (FcChar8 *)mic_buf, strlen(mic_buf), &mic_extents); int mic_size_w = mic_extents.width + padding * 4; - int offset_x = desktop_size + mic_size_w + 40; + int offset_x = desktop_size + layout_size_w + mic_size_w + 35; char time_buf[64]; time_t now = time(NULL); @@ -107,6 +155,7 @@ void widget_datetime(void) { void redraw_widgets(void) { widget_desktop_indicator(); + widget_layout_indicator(); widget_mic_indicator(); widget_datetime(); } |
