Add NeoUI 240x320 UI SDK, migrate all GUI plugins, add Yabasic FFI wrapper and fix camera rotation
This commit is contained in:
1 parent
1f9138f0c6
commit
c137feee0e
59 files changed
+5932
-2128
No files matched your search
@@ -8,8 +8,9 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) optimized f
|
||||
## 2. Repository Layout
|
||||
- `src/sxmo-dwm/`: Patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `SW_LID` slider and locked-key wake handling, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`).
|
||||
- `src/sxmo-dmenu/`: Zero-lag resident DWM menu plugin (`dmenu.so`) and `/tmp/dwm_plugin_dmenu.sock` client (`dmenu` / `xdmenu`), featuring built-in Sxmo menus (`sys`, `applications`, `scripts`, `modem`, `config`, `power`, `audio`, `notifications`, `wm`, `timezone`, `games`, `st`, `nano`, `sthotkeys`) and `fcitx5-t9` XIM input.
|
||||
- `src/dwm-plugins/`: Preloaded C++20 `240x320` DWM plugins and shared headers:
|
||||
- `theme.h`: Unified `.Xresources` / `~/.xthemes/*.xth` parser, proportional font sizing (`theme.baseFontSize`), automatic shade derivation, and live Xft/Pango theme reloading (`PluginTheme`).
|
||||
- `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input.
|
||||
- `src/dwm-plugins/`: Preloaded C++20 `240x320` DWM plugins linked against `libneoui.so` and shared headers:
|
||||
- `theme.h`: Header forwarding to `../neoui/neoui.h` for unified `.Xresources` / `~/.xthemes/*.xth` parsing, proportional font sizing (`theme.baseFontSize`), automatic shade derivation, and live Xft/Pango theme reloading (`PluginTheme`).
|
||||
- `phone_data.h`: Shared X11 geometry (`240x296` below the 24px bar), FIFO IPC (`/tmp/dwm_plugin_<name>.fifo`), softkey chord detection, Sxmo TSV contact/call/SMS parsers, and `libjpeg`/`libpng` helpers.
|
||||
- `dialer_plugin.cpp` (`dialer.so` / `xdialer`), `calllog_plugin.cpp` (`calllog.so` / `xcalllog`), `callscreen_plugin.cpp` (`callscreen.so` / `xcallscreen`), `contacts_plugin.cpp` (`contacts.so` / `xcontacts`), `sms_plugin.cpp` (`sms.so` / `xsms`), `files_plugin.cpp` (`files.so` / `xfiles`), `camera_plugin.cpp` (`camera.so` / `xcamera`), `themes_plugin.cpp` (`themes.so` / `xthemes`), `modem_plugin.cpp` (`modem.so` / `xmodem`), `networks_plugin.cpp` (`networks.so` / `xnetworks` / `xbluetooth`), `ringtones_plugin.cpp` (`ringtones.so` / `xringtones`), `wallpapers_plugin.cpp` (`wallpapers.so` / `xwallpapers` / `xbackground`), `music_plugin.cpp` (`music.so` / `xmusic` / `xplayer`).
|
||||
- `dwm_plugin_runner.c`: Lightweight `/usr/bin/dwm-plugin` launcher symlinked by `xdrawer`, `xdialer`, `xcalllog`, `xcallscreen`, `xcontacts`, `xsms`, `xfiles`, `xcamera`, `xthemes`, `xmodem`, `xnetworks`, `xbluetooth`, `xringtones`, `xwallpapers`, `xbackground`, `xmusic`, `xplayer`, `dmenu`, and `xdmenu`.
|
||||
|
||||
@@ -26,7 +26,7 @@ This manual covers flashing, operating, and customizing **Bananarchy Linux** (`2
|
||||
- **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a Conky desktop clock and status widget (which refreshes automatically when changing time, timezone, or wallpaper, or when logging out), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys.
|
||||
2. **Preloaded resident DWM plugins (`< 2 ms` wakeup)**:
|
||||
- Core phone applications (`dmenu`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`) run as preloaded resident daemons (`dwm-plugin <name> --preload`) that sleep at 0% CPU and open instantaneously over FIFO/socket IPC.
|
||||
- All UI elements share a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11.
|
||||
- All UI elements share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic`, etc.) `240x320` GUI applications.
|
||||
3. **First-class terminal (`st`) and 6-mode `fcitx5-t9` keypad input**:
|
||||
- `st` is patched with HarfBuzz OpenType ligature shaping (`Fira Code` default) and live `.Xresources` reload.
|
||||
- `fcitx5-t9` provides 6 keypad input modes (`abc`, `Abc`, `ABC`, `Sym`, `Ctl`, `123` + `*` long-press `Ctrl+` latch) in a fixed bottom candidate bar (`Y = 290, H = 30`).
|
||||
|
||||
@@ -33,6 +33,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
|
||||
- **6-mode `fcitx5-t9` keypad input**: press `#` to cycle between `abc`, `Abc`, `ABC`, `Sym` (all 32 ASCII punctuation symbols), `Ctl` (`Ctrl` sequences, arrows, `PageUp`/`PageDown`, `F1`–`F12`), and `123` numeric modes with a fixed bottom candidate bar.
|
||||
- **First-class Linux terminal (`st`)**: patched with HarfBuzz OpenType ligatures (`Fira Code` as the default system and terminal font), XIM T9 input, and live theme reloading.
|
||||
- **On-device development, scripting, and gaming**: preinstalled `gcc`/`g++`, `make`, `git`, GNU `coreutils`, GNU `bc`/`dc`, `nano`, `ed`, `sqlite3`, `lua` (`5.5` and `5.4`), `yabasic`, `perl`, `tcl`, the [Janet](https://janet-lang.org/) language and `jpm`, the [Bantam](https://bantam.luxferre.top/) coding agent, `frotz` (interactive fiction), standalone X11 keypad games (`Snake` and `Tetris`), and a full-featured Gambatte-based Game Boy / Game Boy Color emulator (`gambatte` / `gbemu`) with readjustable keypad controls (`B=8`, `Turbo B=5`, `A=9`, `Turbo A=6`, `D-pad`, `Start=2`, `Select=3`, `Palette=*`), 10 color palettes, save states, and File Manager `.gb`/`.gbc` integration.
|
||||
- **NeoUI 240x320 UI SDK (`libneoui.so` + `/usr/include/neoui.h`)**: unified C-compatible FFI and C++20 UI SDK wrapping Xlib, Xft, Pango, `libjpeg`/`libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets (headers, tabs, softkey bars, list/toggle/slider rows, input boxes, progress bars, scrollbars, modals, popup menus, and toasts), keypad/softkey chord handling, and multi-tap text entry—usable from C, C++, or any FFI-capable scripting language such as Yabasic (`frnfn_call` / `frnfn_call$`).
|
||||
|
||||
---
|
||||
|
||||
@@ -65,6 +66,7 @@ bananarchy/
|
||||
├── devices/ # Device definitions, DTBs, and MIPI-DBI panel init sequences
|
||||
├── patches/ # Upstream kernel, EDL, Sxmo, Xlibre, and fcitx5-t9 patch sets
|
||||
├── src/
|
||||
│ ├── neoui/ # NeoUI 240x320 UI SDK (libneoui.so + /usr/include/neoui.h, C FFI & C++20)
|
||||
│ ├── sxmo-dwm/ # Patched sxmo-dwm (240x320 bstack, Pango bar, softkey bar, and plugin API)
|
||||
│ ├── dwm-plugins/ # DWM plugins (dialer, calllog, callscreen, contacts, sms, files, camera,
|
||||
│ │ # themes, modem, networks, ringtones, wallpapers, music), theme.h, and runner
|
||||
|
||||
@@ -0,0 +1,485 @@
|
||||
// ============================================================================
|
||||
// neoui.yab - Yabasic Native C FFI Wrapper for Bananarchy NeoUI (libneoui.so)
|
||||
// ============================================================================
|
||||
// Exposes all NeoUI 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
|
||||
// functions to Yabasic programs via libffi (frnfn_call / frnfn_call$).
|
||||
//
|
||||
// Usage in your Yabasic program:
|
||||
// import neoui
|
||||
// neoui_init("myapp", 0)
|
||||
// ============================================================================
|
||||
|
||||
NEOUI_LIB$ = "/usr/lib/libneoui.so"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geometry Constants (240x320 QVGA)
|
||||
// ----------------------------------------------------------------------------
|
||||
SCREEN_W = 240
|
||||
SCREEN_H = 320
|
||||
TOPBAR_H = 24
|
||||
WIN_X = 0
|
||||
WIN_Y = 24
|
||||
WIN_W = 240
|
||||
WIN_H = 296
|
||||
HEADER_H = 34
|
||||
SOFTBAR_H = 26
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Theme Color Token IDs for neoui_color(color_id)
|
||||
// ----------------------------------------------------------------------------
|
||||
COLOR_BG_MAIN = 0
|
||||
COLOR_BG_BAR = 1
|
||||
COLOR_BG_HEADER = 2
|
||||
COLOR_BG_FOOTER = 3
|
||||
COLOR_BG_OVERLAY = 4
|
||||
COLOR_BG_ALT_EVEN = 5
|
||||
COLOR_BG_ALT_ODD = 6
|
||||
COLOR_BG_INPUT = 7
|
||||
COLOR_BG_INPUT_FOCUS = 8
|
||||
COLOR_BG_BUTTON = 9
|
||||
COLOR_BG_SEARCH = 10
|
||||
COLOR_BG_BUBBLE_IN = 11
|
||||
COLOR_BG_BUBBLE_OUT = 12
|
||||
COLOR_BG_TOAST = 13
|
||||
COLOR_FG_MAIN = 14
|
||||
COLOR_FG_BRIGHT = 15
|
||||
COLOR_FG_MUTED = 16
|
||||
COLOR_SEL_BG = 17
|
||||
COLOR_SEL_FG = 18
|
||||
COLOR_ACCENT = 19
|
||||
COLOR_ACCENT_ALT = 20
|
||||
COLOR_HIGHLIGHT = 21
|
||||
COLOR_BORDER = 22
|
||||
COLOR_DIVIDER = 23
|
||||
COLOR_SUCCESS = 24
|
||||
COLOR_INFO = 25
|
||||
COLOR_WARNING = 26
|
||||
COLOR_DANGER = 27
|
||||
COLOR_DANGER_BG = 28
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Proportional Pango Font Roles
|
||||
// ----------------------------------------------------------------------------
|
||||
FONT_SMALL = 0
|
||||
FONT_MAIN = 1
|
||||
FONT_ICON = 2
|
||||
FONT_LARGE = 3
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Semantic Xft Text Color Roles
|
||||
// ----------------------------------------------------------------------------
|
||||
TEXT_WHITE = 0
|
||||
TEXT_LIGHT = 1
|
||||
TEXT_MUTED = 2
|
||||
TEXT_YELLOW = 3
|
||||
TEXT_GREEN = 4
|
||||
TEXT_BLUE = 5
|
||||
TEXT_ORANGE = 6
|
||||
TEXT_RED = 7
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Event Types returned by neoui_poll_event(timeout_ms)
|
||||
// ----------------------------------------------------------------------------
|
||||
EV_NONE = 0
|
||||
EV_EXPOSE = 1
|
||||
EV_KEY_PRESS = 2
|
||||
EV_KEY_RELEASE = 3
|
||||
EV_SOFTKEY_LEFT = 4
|
||||
EV_SOFTKEY_RIGHT = 5
|
||||
EV_SOFTKEY_CHORD = 6
|
||||
EV_FIFO_CMD = 7
|
||||
EV_THEME_RELOAD = 8
|
||||
EV_CLOSE_REQ = 9
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Logical Keypad Key Codes returned by neoui_event_key()
|
||||
// ----------------------------------------------------------------------------
|
||||
KEY_NONE = 0
|
||||
KEY_UP = 1
|
||||
KEY_DOWN = 2
|
||||
KEY_LEFT = 3
|
||||
KEY_RIGHT = 4
|
||||
KEY_OK = 5
|
||||
KEY_BACK = 6
|
||||
KEY_CALL = 7
|
||||
KEY_END = 8
|
||||
KEY_SOFT_LEFT = 9
|
||||
KEY_SOFT_RIGHT = 10
|
||||
KEY_SPACE = 32
|
||||
KEY_HASH = 35
|
||||
KEY_STAR = 42
|
||||
KEY_PLUS = 43
|
||||
KEY_0 = 48
|
||||
KEY_1 = 49
|
||||
KEY_2 = 50
|
||||
KEY_3 = 51
|
||||
KEY_4 = 52
|
||||
KEY_5 = 53
|
||||
KEY_6 = 54
|
||||
KEY_7 = 55
|
||||
KEY_8 = 56
|
||||
KEY_9 = 57
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Multi-Tap Input Modes
|
||||
// ----------------------------------------------------------------------------
|
||||
INPUT_ABC_TITLE = 0
|
||||
INPUT_ABC_LOWER = 1
|
||||
INPUT_ABC_UPPER = 2
|
||||
INPUT_123 = 3
|
||||
INPUT_SYM = 4
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Image Scaling Modes
|
||||
// ----------------------------------------------------------------------------
|
||||
SCALE_FIT = 0
|
||||
SCALE_FILL = 1
|
||||
SCALE_STRETCH = 2
|
||||
|
||||
// ============================================================================
|
||||
// 1. Window & Daemon Lifecycle
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_init(app_name$, preload_mode)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_init", "string", app_name$, "int32", preload_mode)
|
||||
end sub
|
||||
|
||||
export sub neoui_init_ex(app_name$, res_name$, res_class$, win_title$, x, y, w, h, override_redirect, preload_mode)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_init_ex", "string", app_name$, "string", res_name$, "string", res_class$, "string", win_title$, "int32", x, "int32", y, "int32", w, "int32", h, "int32", override_redirect, "int32", preload_mode)
|
||||
end sub
|
||||
|
||||
export sub neoui_shutdown()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_shutdown")
|
||||
end sub
|
||||
|
||||
export sub neoui_show()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_show")
|
||||
end sub
|
||||
|
||||
export sub neoui_hide()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_hide")
|
||||
end sub
|
||||
|
||||
export sub neoui_is_visible()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_is_visible")
|
||||
end sub
|
||||
|
||||
export sub neoui_raise_and_grab()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_raise_and_grab")
|
||||
end sub
|
||||
|
||||
export sub neoui_ungrab()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_ungrab")
|
||||
end sub
|
||||
|
||||
export sub neoui_width()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_width")
|
||||
end sub
|
||||
|
||||
export sub neoui_height()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_height")
|
||||
end sub
|
||||
|
||||
export sub neoui_begin_frame()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_begin_frame")
|
||||
end sub
|
||||
|
||||
export sub neoui_end_frame()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_end_frame")
|
||||
end sub
|
||||
|
||||
export sub neoui_flush()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_flush")
|
||||
end sub
|
||||
|
||||
// ============================================================================
|
||||
// 2. Unified .Xresources / .xth Theme & Icon Resolution
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_reload_theme()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_reload_theme")
|
||||
end sub
|
||||
|
||||
export sub neoui_check_reload_theme()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_check_reload_theme")
|
||||
end sub
|
||||
|
||||
export sub neoui_apply_theme_file(xth_path$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_apply_theme_file", "string", xth_path$)
|
||||
end sub
|
||||
|
||||
export sub neoui_broadcast_theme_reload(skip_plugin$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_broadcast_theme_reload", "string", skip_plugin$)
|
||||
end sub
|
||||
|
||||
export sub neoui_theme_name$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_theme_name", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_font_face$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_font_face", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_icon_font_face$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_icon_font_face", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_base_font_size()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_base_font_size")
|
||||
end sub
|
||||
|
||||
export sub neoui_font_size(font_role)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_font_size", "int32", font_role)
|
||||
end sub
|
||||
|
||||
export sub neoui_color(color_id)
|
||||
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_color", "int32", color_id)
|
||||
end sub
|
||||
|
||||
export sub neoui_adjust_rgb(rgb, delta)
|
||||
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_adjust_rgb", "uint32", rgb, "int32", delta)
|
||||
end sub
|
||||
|
||||
export sub neoui_blend_rgb(c1, c2, weight2_pct)
|
||||
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_blend_rgb", "uint32", c1, "uint32", c2, "int32", weight2_pct)
|
||||
end sub
|
||||
|
||||
export sub neoui_parse_hex_rgb(hex_str$, fallback_rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_parse_hex_rgb", "string", hex_str$, "uint32", fallback_rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_format_hex_rgb$(rgb)
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_format_hex_rgb", "uint32", rgb, "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_icon$(icon_name$)
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_icon", "string", icon_name$, "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
// ============================================================================
|
||||
// 3. Drawing Primitives & Text Rendering
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_clear(rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_clear", "uint32", rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_fill_rect(x, y, w, h, rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_fill_rect", "int32", x, "int32", y, "int32", w, "int32", h, "uint32", rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_rect(x, y, w, h, rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_rect", "int32", x, "int32", y, "int32", w, "int32", h, "uint32", rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_line(x1, y1, x2, y2, rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_line", "int32", x1, "int32", y1, "int32", x2, "int32", y2, "uint32", rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_set_clip(x, y, w, h)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_set_clip", "int32", x, "int32", y, "int32", w, "int32", h)
|
||||
end sub
|
||||
|
||||
export sub neoui_reset_clip()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_reset_clip")
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_text(font_role, color_role, x, y, h, text$, max_w)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", h, "string", text$, "int32", max_w)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_text_centered(font_role, color_role, x, y, w, h, text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_centered", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", w, "int32", h, "string", text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_text_right(font_role, color_role, right_x, y, h, text$, max_w)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_right", "int32", font_role, "int32", color_role, "int32", right_x, "int32", y, "int32", h, "string", text$, "int32", max_w)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_text_wrapped(font_role, color_role, x, y, w, h, text$, scroll_line)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_wrapped", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", w, "int32", h, "string", text$, "int32", scroll_line)
|
||||
end sub
|
||||
|
||||
export sub neoui_text_width(font_role, text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_text_width", "int32", font_role, "string", text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_tail_fit_text$(font_role, text$, max_w)
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_tail_fit_text", "int32", font_role, "string", text$, "int32", max_w, "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_image_file(path$, x, y, w, h, scale_mode)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_image_file", "string", path$, "int32", x, "int32", y, "int32", w, "int32", h, "int32", scale_mode)
|
||||
end sub
|
||||
|
||||
// ============================================================================
|
||||
// 4. Standardized OS Shell UI Components (Widgets)
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_draw_header(icon_str$, icon_color_role, title$, right_badge$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_header", "string", icon_str$, "int32", icon_color_role, "string", title$, "string", right_badge$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_header_ex(h, icon_str$, icon_color_role, title$, title_color_role, right_badge$, right_color_role)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_header_ex", "int32", h, "string", icon_str$, "int32", icon_color_role, "string", title$, "int32", title_color_role, "string", right_badge$, "int32", right_color_role)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_tabs(pipe_labels$, active_idx, y, h)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_tabs", "string", pipe_labels$, "int32", active_idx, "int32", y, "int32", h)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_softkeys(left_label$, center_label$, right_label$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_softkeys", "string", left_label$, "string", center_label$, "string", right_label$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_softkeys_ex(left_label$, center_label$, right_label$, center_color_role)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_softkeys_ex", "string", left_label$, "string", center_label$, "string", right_label$, "int32", center_color_role)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_list_row(row_index, y, h, is_selected, icon_str$, icon_color_role, title$, subtitle$, right_text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_list_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", title$, "string", subtitle$, "string", right_text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_slider_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, pct, value_text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_slider_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", label$, "int32", pct, "string", value_text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_toggle_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, is_on, state_text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_toggle_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", label$, "int32", is_on, "string", state_text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_button(x, y, w, h, is_selected, is_danger, icon_str$, label$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_button", "int32", x, "int32", y, "int32", w, "int32", h, "int32", is_selected, "int32", is_danger, "string", icon_str$, "string", label$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_input_box(x, y, w, h, is_focused, label$, value$, placeholder$, password_mask)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_input_box", "int32", x, "int32", y, "int32", w, "int32", h, "int32", is_focused, "string", label$, "string", value$, "string", placeholder$, "int32", password_mask)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_progress_bar(x, y, w, h, pct, fill_rgb)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_progress_bar", "int32", x, "int32", y, "int32", w, "int32", h, "int32", pct, "uint32", fill_rgb)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_scrollbar(x, y, h, total_items, visible_items, scroll_offset)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_scrollbar", "int32", x, "int32", y, "int32", h, "int32", total_items, "int32", visible_items, "int32", scroll_offset)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_modal_box(x, y, w, h, icon_str$, icon_color_role, title$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_modal_box", "int32", x, "int32", y, "int32", w, "int32", h, "string", icon_str$, "int32", icon_color_role, "string", title$)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_confirm_dialog(title$, line1$, line2$, no_label$, yes_label$, selected_yes)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_confirm_dialog", "string", title$, "string", line1$, "string", line2$, "string", no_label$, "string", yes_label$, "int32", selected_yes)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_menu_popup(pipe_items$, pipe_icons$, selected_idx, max_visible_rows)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_menu_popup", "string", pipe_items$, "string", pipe_icons$, "int32", selected_idx, "int32", max_visible_rows)
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_toast(message$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_toast", "string", message$)
|
||||
end sub
|
||||
|
||||
export sub neoui_show_toast(message$, duration_ms)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_show_toast", "string", message$, "int32", duration_ms)
|
||||
end sub
|
||||
|
||||
export sub neoui_clear_toast()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_clear_toast")
|
||||
end sub
|
||||
|
||||
// ============================================================================
|
||||
// 5. Event Loop, Keypad & Multi-Tap Input Management
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_poll_event(timeout_ms)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_poll_event", "int32", timeout_ms)
|
||||
end sub
|
||||
|
||||
export sub neoui_event_key()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_key")
|
||||
end sub
|
||||
|
||||
export sub neoui_event_keycode()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_keycode")
|
||||
end sub
|
||||
|
||||
export sub neoui_event_keysym()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_keysym")
|
||||
end sub
|
||||
|
||||
export sub neoui_event_command$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_event_command", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_set_chord_xdrawer(enabled)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_set_chord_xdrawer", "int32", enabled)
|
||||
end sub
|
||||
|
||||
export sub neoui_input_reset(initial_text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_reset", "string", initial_text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_input_set_text(text$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_set_text", "string", text$)
|
||||
end sub
|
||||
|
||||
export sub neoui_input_get_text$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_get_text", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_set_mode(mode)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_set_mode", "int32", mode)
|
||||
end sub
|
||||
|
||||
export sub neoui_input_get_mode()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_get_mode")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_cycle_mode()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_cycle_mode")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_mode_badge$()
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_mode_badge", "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_feed_key(neo_key)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_feed_key", "int32", neo_key)
|
||||
end sub
|
||||
|
||||
export sub neoui_input_commit_tap()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_commit_tap")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_backspace()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_backspace")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_is_tap_active()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_is_tap_active")
|
||||
end sub
|
||||
|
||||
export sub neoui_input_candidate_bar$(idle_hint$)
|
||||
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_candidate_bar", "string", idle_hint$, "options", "copy_string_result")
|
||||
end sub
|
||||
|
||||
export sub neoui_draw_multitap_bar(x, y, w, h, idle_hint$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_multitap_bar", "int32", x, "int32", y, "int32", w, "int32", h, "string", idle_hint$)
|
||||
end sub
|
||||
|
||||
// ============================================================================
|
||||
// 6. System & IPC Utilities
|
||||
// ============================================================================
|
||||
|
||||
export sub neoui_send_plugin_cmd(plugin_name$, cmd$)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_send_plugin_cmd", "string", plugin_name$, "string", cmd$)
|
||||
end sub
|
||||
|
||||
export sub neoui_vibrate(duration_ms)
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_vibrate", "int32", duration_ms)
|
||||
end sub
|
||||
|
||||
export sub neoui_now_ms()
|
||||
return frnfn_call(NEOUI_LIB$, "int32", "neoui_now_ms")
|
||||
end sub
|
||||
+414
@@ -0,0 +1,414 @@
|
||||
#!/usr/bin/yabasic
|
||||
// ============================================================================
|
||||
// neoui_demo.yab - Bananarchy NeoUI SDK Showcase for Yabasic
|
||||
// ============================================================================
|
||||
// Demonstrates:
|
||||
// - Live .Xresources / ~/.xthemes/*.xth theme resolution & hot-reload
|
||||
// - Header bar, 3-Tab navigation bar, and Softkey bar
|
||||
// - List rows, Toggle rows, Slider rows, Progress bars, and Buttons
|
||||
// - Multi-tap T9 keypad text input with scrolling candidate bar & mode badge
|
||||
// - Custom drawing primitives, Nerd Font icons, and theme color swatches
|
||||
// - Popup action menu, Confirmation dialog, and Toast notification banner
|
||||
//
|
||||
// Controls:
|
||||
// - 1 / 2 / 3 (when not typing): Switch tabs (Widgets / Input / Theme)
|
||||
// - Up / Down: Navigate rows or menu items
|
||||
// - Left / Right: Adjust sliders, switch tabs, or toggle No/Yes in dialog
|
||||
// - OK (Enter): Toggle item / Submit text / Trigger action
|
||||
// - Left Softkey (F1): Open Action Menu
|
||||
// - Right Softkey (F2) / Backspace: Close modal / Delete char / Exit
|
||||
// - Both Softkeys together: Open Bananarchy XDrawer overlay
|
||||
// ============================================================================
|
||||
|
||||
import neoui
|
||||
|
||||
if neoui_init("neoui_demo", 0) = 0 then
|
||||
print "Failed to initialize NeoUI X11 window"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
// Tab index: 0 = Widgets, 1 = Input, 2 = Theme & Canvas
|
||||
active_tab = 0
|
||||
|
||||
// Tab 0 (Widgets) state
|
||||
widget_sel = 0
|
||||
wifi_enabled = 1
|
||||
torch_enabled = 0
|
||||
volume_pct = 75
|
||||
bright_pct = 80
|
||||
progress_pct = 45
|
||||
|
||||
// Tab 1 (Multi-Tap Input) state
|
||||
input_focus = 0
|
||||
dim notes$(10)
|
||||
notes$(0) = "Welcome to NeoUI SDK!"
|
||||
notes$(1) = "Try typing with 0-9 keys"
|
||||
notes$(2) = "Press # to switch mode"
|
||||
note_count = 3
|
||||
neoui_input_reset("Bananarchy ")
|
||||
|
||||
// Modal state: 0 = None, 1 = Popup Menu, 2 = Confirm Reset Dialog
|
||||
modal_mode = 0
|
||||
menu_sel = 0
|
||||
confirm_yes = 0
|
||||
|
||||
sub render_widgets_tab()
|
||||
local y, wifi_txt$, torch_txt$, vol_txt$, brt_txt$
|
||||
|
||||
y = 60
|
||||
if wifi_enabled then
|
||||
wifi_txt$ = "Connected"
|
||||
else
|
||||
wifi_txt$ = "Off"
|
||||
fi
|
||||
neoui_draw_toggle_row(0, y, 36, widget_sel = 0, neoui_icon$("wifi"), neoui.TEXT_BLUE, "Wi-Fi Radio", wifi_enabled, wifi_txt$)
|
||||
|
||||
y = y + 36
|
||||
if torch_enabled then
|
||||
torch_txt$ = "Active"
|
||||
else
|
||||
torch_txt$ = "Off"
|
||||
fi
|
||||
neoui_draw_toggle_row(1, y, 36, widget_sel = 1, neoui_icon$("torch"), neoui.TEXT_YELLOW, "Flashlight", torch_enabled, torch_txt$)
|
||||
|
||||
y = y + 36
|
||||
vol_txt$ = str$(volume_pct) + "%"
|
||||
neoui_draw_slider_row(2, y, 38, widget_sel = 2, neoui_icon$("speaker"), neoui.TEXT_GREEN, "Speaker Vol", volume_pct, vol_txt$)
|
||||
|
||||
y = y + 38
|
||||
brt_txt$ = str$(bright_pct) + "%"
|
||||
neoui_draw_slider_row(3, y, 38, widget_sel = 3, neoui_icon$("sun"), neoui.TEXT_ORANGE, "Backlight", bright_pct, brt_txt$)
|
||||
|
||||
y = y + 42
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Task Progress (" + str$(progress_pct) + "%)", 160)
|
||||
neoui_draw_progress_bar(8, y + 15, 224, 10, progress_pct, neoui_color(neoui.COLOR_ACCENT))
|
||||
|
||||
y = y + 30
|
||||
neoui_draw_button(12, y, 104, 26, widget_sel = 4, 0, neoui_icon$("check"), "Step +15%")
|
||||
neoui_draw_button(124, y, 104, 26, widget_sel = 5, 1, neoui_icon$("trash"), "Reset All")
|
||||
|
||||
neoui_draw_scrollbar(236, 60, 210, 6, 6, 0)
|
||||
end sub
|
||||
|
||||
sub render_input_tab()
|
||||
local i, y, txt$, badge$
|
||||
|
||||
txt$ = neoui_input_get_text$()
|
||||
badge$ = neoui_input_mode_badge$()
|
||||
|
||||
neoui_draw_input_box(8, 64, 224, 42, input_focus = 0, "Multi-Tap Keypad Input [" + badge$ + "]", txt$, "Type with 0-9, # mode...", 0)
|
||||
|
||||
neoui_draw_button(8, 110, 108, 24, input_focus = 1, 0, neoui_icon$("plus"), "Add Note")
|
||||
neoui_draw_button(124, 110, 108, 24, input_focus = 2, 0, neoui_icon$("refresh"), "Clear Text")
|
||||
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 8, 138, 16, "Saved Notes (" + str$(note_count) + "):", 220)
|
||||
|
||||
y = 156
|
||||
for i = 0 to note_count - 1
|
||||
if y + 28 <= 246 then
|
||||
neoui_draw_list_row(i, y, 28, input_focus = (3 + i), neoui_icon$("edit"), neoui.TEXT_BLUE, notes$(i), "", "#" + str$(i + 1))
|
||||
y = y + 28
|
||||
fi
|
||||
next i
|
||||
|
||||
if input_focus = 0 then
|
||||
neoui_draw_multitap_bar(0, 248, 240, 22, "0-9:Type 1:Sym #:Mode OK:Add")
|
||||
fi
|
||||
end sub
|
||||
|
||||
sub render_theme_tab()
|
||||
local y, c_id, sx, sy, sw, sh, rgb
|
||||
|
||||
y = 64
|
||||
neoui_fill_rect(8, y, 224, 68, neoui_color(neoui.COLOR_BG_ALT_ODD))
|
||||
neoui_draw_rect(8, y, 224, 68, neoui_color(neoui.COLOR_BORDER))
|
||||
|
||||
neoui_draw_text(neoui.FONT_MAIN, neoui.TEXT_YELLOW, 14, y + 4, 18, "Theme: " + neoui_theme_name$(), 210)
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_LIGHT, 14, y + 24, 16, "Font: " + neoui_font_face$() + " (" + str$(neoui_base_font_size()) + "px)", 210)
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 14, y + 42, 16, "BG: " + neoui_format_hex_rgb$(neoui_color(neoui.COLOR_BG_MAIN)) + " ACC: " + neoui_format_hex_rgb$(neoui_color(neoui.COLOR_ACCENT)), 210)
|
||||
|
||||
y = 138
|
||||
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_WHITE, 8, y, 16, "Active .Xresources Palette Swatches:", 224)
|
||||
|
||||
y = 158
|
||||
sw = 26
|
||||
sh = 22
|
||||
for c_id = 0 to 15
|
||||
sx = 8 + mod(c_id, 8) * 28
|
||||
sy = y + int(c_id / 8) * 26
|
||||
rgb = neoui_color(c_id + 13)
|
||||
neoui_fill_rect(sx, sy, sw, sh, rgb)
|
||||
neoui_draw_rect(sx, sy, sw, sh, neoui_color(neoui.COLOR_BORDER))
|
||||
next c_id
|
||||
|
||||
y = 214
|
||||
neoui_fill_rect(8, y, 224, 48, neoui_color(neoui.COLOR_BG_HEADER))
|
||||
neoui_draw_rect(8, y, 224, 48, neoui_color(neoui.COLOR_ACCENT))
|
||||
neoui_draw_line(14, y + 24, 226, y + 24, neoui_color(neoui.COLOR_DIVIDER))
|
||||
neoui_draw_text_centered(neoui.FONT_ICON, neoui.TEXT_YELLOW, 8, y + 2, 224, 20, neoui_icon$("phone") + " " + neoui_icon$("sms") + " " + neoui_icon$("music") + " " + neoui_icon$("camera") + " " + neoui_icon$("theme") + " " + neoui_icon$("wifi"))
|
||||
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, y + 26, 224, 18, "Press OK to hot-reload .Xresources")
|
||||
end sub
|
||||
|
||||
sub render_all()
|
||||
local badge$, mid_lbl$, right_lbl$
|
||||
|
||||
neoui_begin_frame()
|
||||
|
||||
if active_tab = 1 then
|
||||
badge$ = neoui_input_mode_badge$()
|
||||
else
|
||||
badge$ = neoui_theme_name$()
|
||||
fi
|
||||
|
||||
neoui_draw_header(neoui_icon$("theme"), neoui.TEXT_YELLOW, "NeoUI SDK Demo", badge$)
|
||||
neoui_draw_tabs("1:Widgets|2:Input|3:Theme", active_tab, 34, 24)
|
||||
|
||||
if active_tab = 0 then
|
||||
render_widgets_tab()
|
||||
mid_lbl$ = "Toggle"
|
||||
right_lbl$ = "Quit"
|
||||
elsif active_tab = 1 then
|
||||
render_input_tab()
|
||||
mid_lbl$ = "Add"
|
||||
if input_focus = 0 and len(neoui_input_get_text$()) > 0 then
|
||||
right_lbl$ = "Del"
|
||||
else
|
||||
right_lbl$ = "Quit"
|
||||
fi
|
||||
else
|
||||
render_theme_tab()
|
||||
mid_lbl$ = "Reload"
|
||||
right_lbl$ = "Quit"
|
||||
fi
|
||||
|
||||
if modal_mode = 1 then
|
||||
neoui_draw_menu_popup("Show Toast Banner|Vibrate Phone|Reload Theme|Reset Demo State|Quit Demo", neoui_icon$("bell") + "|" + neoui_icon$("audio") + "|" + neoui_icon$("refresh") + "|" + neoui_icon$("trash") + "|" + neoui_icon$("close"), menu_sel, 5)
|
||||
neoui_draw_softkeys("Close", "Select", "Back")
|
||||
elsif modal_mode = 2 then
|
||||
neoui_draw_confirm_dialog("Reset Demo State?", "Restore all sliders, toggles,", "and notes to default values?", "Cancel", "Reset", confirm_yes)
|
||||
neoui_draw_softkeys("Cancel", "Confirm", "Back")
|
||||
else
|
||||
neoui_draw_softkeys("Menu", mid_lbl$, right_lbl$)
|
||||
fi
|
||||
|
||||
neoui_end_frame()
|
||||
end sub
|
||||
|
||||
sub reset_demo_state()
|
||||
wifi_enabled = 1
|
||||
torch_enabled = 0
|
||||
volume_pct = 75
|
||||
bright_pct = 80
|
||||
progress_pct = 45
|
||||
note_count = 3
|
||||
notes$(0) = "Welcome to NeoUI SDK!"
|
||||
notes$(1) = "Try typing with 0-9 keys"
|
||||
notes$(2) = "Press # to switch mode"
|
||||
neoui_input_reset("Bananarchy ")
|
||||
neoui_show_toast("Demo state reset!", 1800)
|
||||
end sub
|
||||
|
||||
sub add_current_note()
|
||||
local t$
|
||||
neoui_input_commit_tap()
|
||||
t$ = neoui_input_get_text$()
|
||||
if len(t$) = 0 then
|
||||
neoui_show_toast("Input is empty!", 1500)
|
||||
return
|
||||
fi
|
||||
if note_count < 10 then
|
||||
notes$(note_count) = t$
|
||||
note_count = note_count + 1
|
||||
else
|
||||
notes$(9) = t$
|
||||
fi
|
||||
neoui_input_reset("")
|
||||
neoui_show_toast("Note added!", 1500)
|
||||
end sub
|
||||
|
||||
render_all()
|
||||
|
||||
running = 1
|
||||
while running
|
||||
ev = neoui_poll_event(250)
|
||||
|
||||
if ev = neoui.EV_CLOSE_REQ then
|
||||
running = 0
|
||||
elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then
|
||||
render_all()
|
||||
elsif ev = neoui.EV_SOFTKEY_LEFT then
|
||||
if modal_mode = 0 then
|
||||
modal_mode = 1
|
||||
menu_sel = 0
|
||||
else
|
||||
modal_mode = 0
|
||||
fi
|
||||
render_all()
|
||||
elsif ev = neoui.EV_SOFTKEY_RIGHT then
|
||||
if modal_mode <> 0 then
|
||||
modal_mode = 0
|
||||
render_all()
|
||||
elsif active_tab = 1 and input_focus = 0 and len(neoui_input_get_text$()) > 0 then
|
||||
neoui_input_backspace()
|
||||
render_all()
|
||||
else
|
||||
running = 0
|
||||
fi
|
||||
elsif ev = neoui.EV_KEY_PRESS then
|
||||
k = neoui_event_key()
|
||||
|
||||
if modal_mode = 1 then
|
||||
if k = neoui.KEY_UP then
|
||||
menu_sel = mod(menu_sel + 4, 5)
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
menu_sel = mod(menu_sel + 1, 5)
|
||||
elsif k = neoui.KEY_BACK then
|
||||
modal_mode = 0
|
||||
elsif k = neoui.KEY_OK then
|
||||
modal_mode = 0
|
||||
if menu_sel = 0 then
|
||||
neoui_show_toast("Hello from Yabasic NeoUI!", 2000)
|
||||
elsif menu_sel = 1 then
|
||||
neoui_vibrate(60)
|
||||
neoui_show_toast("Vibrated 60 ms", 1500)
|
||||
elsif menu_sel = 2 then
|
||||
neoui_reload_theme()
|
||||
neoui_show_toast("Theme reloaded!", 1500)
|
||||
elsif menu_sel = 3 then
|
||||
modal_mode = 2
|
||||
confirm_yes = 1
|
||||
elsif menu_sel = 4 then
|
||||
running = 0
|
||||
fi
|
||||
fi
|
||||
render_all()
|
||||
|
||||
elsif modal_mode = 2 then
|
||||
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
|
||||
confirm_yes = 1 - confirm_yes
|
||||
elsif k = neoui.KEY_BACK then
|
||||
modal_mode = 0
|
||||
elsif k = neoui.KEY_OK then
|
||||
modal_mode = 0
|
||||
if confirm_yes then
|
||||
reset_demo_state()
|
||||
fi
|
||||
fi
|
||||
render_all()
|
||||
|
||||
else
|
||||
// Normal tab navigation & interaction
|
||||
if active_tab = 1 and input_focus = 0 then
|
||||
// When focused on the text input box, feed digits/star/hash to multi-tap
|
||||
if k = neoui.KEY_UP then
|
||||
input_focus = 2 + note_count
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
input_focus = 1
|
||||
elsif k = neoui.KEY_LEFT then
|
||||
if neoui_input_is_tap_active() then
|
||||
neoui_input_commit_tap()
|
||||
else
|
||||
active_tab = 0
|
||||
fi
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
if neoui_input_is_tap_active() then
|
||||
neoui_input_commit_tap()
|
||||
else
|
||||
active_tab = 2
|
||||
fi
|
||||
elsif k = neoui.KEY_OK then
|
||||
add_current_note()
|
||||
else
|
||||
neoui_input_feed_key(k)
|
||||
fi
|
||||
render_all()
|
||||
|
||||
else
|
||||
// Global tab shortcuts 1 / 2 / 3 when not typing in input box
|
||||
if k = neoui.KEY_1 then
|
||||
active_tab = 0
|
||||
elsif k = neoui.KEY_2 then
|
||||
active_tab = 1
|
||||
elsif k = neoui.KEY_3 then
|
||||
active_tab = 2
|
||||
elsif k = neoui.KEY_BACK then
|
||||
running = 0
|
||||
elsif active_tab = 0 then
|
||||
if k = neoui.KEY_UP then
|
||||
widget_sel = mod(widget_sel + 5, 6)
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
widget_sel = mod(widget_sel + 1, 6)
|
||||
elsif k = neoui.KEY_LEFT then
|
||||
if widget_sel = 2 then
|
||||
volume_pct = max(0, volume_pct - 5)
|
||||
elsif widget_sel = 3 then
|
||||
bright_pct = max(5, bright_pct - 5)
|
||||
else
|
||||
active_tab = 2
|
||||
fi
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
if widget_sel = 2 then
|
||||
volume_pct = min(100, volume_pct + 5)
|
||||
elsif widget_sel = 3 then
|
||||
bright_pct = min(100, bright_pct + 5)
|
||||
else
|
||||
active_tab = 1
|
||||
fi
|
||||
elsif k = neoui.KEY_OK then
|
||||
if widget_sel = 0 then
|
||||
wifi_enabled = 1 - wifi_enabled
|
||||
neoui_show_toast("Wi-Fi toggled", 1200)
|
||||
elsif widget_sel = 1 then
|
||||
torch_enabled = 1 - torch_enabled
|
||||
neoui_show_toast("Flashlight toggled", 1200)
|
||||
elsif widget_sel = 4 then
|
||||
progress_pct = mod(progress_pct + 15, 105)
|
||||
if progress_pct > 100 then progress_pct = 0 fi
|
||||
elsif widget_sel = 5 then
|
||||
modal_mode = 2
|
||||
confirm_yes = 1
|
||||
fi
|
||||
fi
|
||||
elsif active_tab = 1 then
|
||||
total_focus = 3 + note_count
|
||||
if k = neoui.KEY_UP then
|
||||
input_focus = mod(input_focus + total_focus - 1, total_focus)
|
||||
elsif k = neoui.KEY_DOWN then
|
||||
input_focus = mod(input_focus + 1, total_focus)
|
||||
elsif k = neoui.KEY_LEFT then
|
||||
if input_focus = 2 then
|
||||
input_focus = 1
|
||||
else
|
||||
active_tab = 0
|
||||
fi
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
if input_focus = 1 then
|
||||
input_focus = 2
|
||||
else
|
||||
active_tab = 2
|
||||
fi
|
||||
elsif k = neoui.KEY_OK then
|
||||
if input_focus = 1 then
|
||||
add_current_note()
|
||||
elsif input_focus = 2 then
|
||||
neoui_input_reset("")
|
||||
neoui_show_toast("Input cleared", 1200)
|
||||
fi
|
||||
fi
|
||||
elsif active_tab = 2 then
|
||||
if k = neoui.KEY_LEFT then
|
||||
active_tab = 1
|
||||
elsif k = neoui.KEY_RIGHT then
|
||||
active_tab = 0
|
||||
elsif k = neoui.KEY_OK then
|
||||
neoui_reload_theme()
|
||||
neoui_show_toast("Reloaded .Xresources theme!", 1600)
|
||||
fi
|
||||
fi
|
||||
render_all()
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
wend
|
||||
|
||||
neoui_shutdown()
|
||||
@@ -124,7 +124,7 @@ take_photo() {
|
||||
|
||||
if ! ffmpeg -hide_banner -loglevel error \
|
||||
-f rawvideo -pixel_format rgb24 -video_size 800x600 \
|
||||
-i "$frame_tmp" -frames:v 1 -y "$target_path"; then
|
||||
-i "$frame_tmp" -vf "transpose=1" -frames:v 1 -y "$target_path"; then
|
||||
rm -f "$frame_tmp"
|
||||
echo "bananarchy-photo: ffmpeg failed to encode $target_path" >&2
|
||||
notify_msg "Photo encoding failed"
|
||||
|
||||
@@ -0,0 +1,575 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// NeoUI - Bananarchy 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
|
||||
// Provides both a C-compatible FFI (libneoui.so) and C++20 SDK classes.
|
||||
// Note: Every extern "C" function returns int, uint32_t, or const char* (never
|
||||
// void) so that FFI callers such as Yabasic frnfn_call / frnfn_call$ work
|
||||
// directly without void-return limitations.
|
||||
|
||||
#ifndef BANANARCHY_NEOUI_H
|
||||
#define BANANARCHY_NEOUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Standard Bananarchy 240x320 QVGA geometry constants
|
||||
enum NeoGeometry {
|
||||
NEO_SCREEN_W = 240,
|
||||
NEO_SCREEN_H = 320,
|
||||
NEO_TOPBAR_H = 24,
|
||||
NEO_WIN_X = 0,
|
||||
NEO_WIN_Y = 24,
|
||||
NEO_WIN_W = 240,
|
||||
NEO_WIN_H = 296,
|
||||
NEO_HEADER_H = 34,
|
||||
NEO_SOFTBAR_H = 26
|
||||
};
|
||||
|
||||
// Theme color token IDs for neoui_color(color_id)
|
||||
enum NeoColorId {
|
||||
NEO_COLOR_BG_MAIN = 0,
|
||||
NEO_COLOR_BG_BAR = 1,
|
||||
NEO_COLOR_BG_HEADER = 2,
|
||||
NEO_COLOR_BG_FOOTER = 3,
|
||||
NEO_COLOR_BG_OVERLAY = 4,
|
||||
NEO_COLOR_BG_ALT_EVEN = 5,
|
||||
NEO_COLOR_BG_ALT_ODD = 6,
|
||||
NEO_COLOR_BG_INPUT = 7,
|
||||
NEO_COLOR_BG_INPUT_FOCUS = 8,
|
||||
NEO_COLOR_BG_BUTTON = 9,
|
||||
NEO_COLOR_BG_SEARCH = 10,
|
||||
NEO_COLOR_BG_BUBBLE_IN = 11,
|
||||
NEO_COLOR_BG_BUBBLE_OUT = 12,
|
||||
NEO_COLOR_BG_TOAST = 13,
|
||||
NEO_COLOR_FG_MAIN = 14,
|
||||
NEO_COLOR_FG_BRIGHT = 15,
|
||||
NEO_COLOR_FG_MUTED = 16,
|
||||
NEO_COLOR_SEL_BG = 17,
|
||||
NEO_COLOR_SEL_FG = 18,
|
||||
NEO_COLOR_ACCENT = 19,
|
||||
NEO_COLOR_ACCENT_ALT = 20,
|
||||
NEO_COLOR_HIGHLIGHT = 21,
|
||||
NEO_COLOR_BORDER = 22,
|
||||
NEO_COLOR_DIVIDER = 23,
|
||||
NEO_COLOR_SUCCESS = 24,
|
||||
NEO_COLOR_INFO = 25,
|
||||
NEO_COLOR_WARNING = 26,
|
||||
NEO_COLOR_DANGER = 27,
|
||||
NEO_COLOR_DANGER_BG = 28
|
||||
};
|
||||
|
||||
// Proportional Pango font roles
|
||||
enum NeoFontRole {
|
||||
NEO_FONT_SMALL = 0,
|
||||
NEO_FONT_MAIN = 1,
|
||||
NEO_FONT_ICON = 2,
|
||||
NEO_FONT_LARGE = 3
|
||||
};
|
||||
|
||||
// Semantic Xft text color roles
|
||||
enum NeoTextColor {
|
||||
NEO_TEXT_WHITE = 0,
|
||||
NEO_TEXT_LIGHT = 1,
|
||||
NEO_TEXT_MUTED = 2,
|
||||
NEO_TEXT_YELLOW = 3,
|
||||
NEO_TEXT_GREEN = 4,
|
||||
NEO_TEXT_BLUE = 5,
|
||||
NEO_TEXT_ORANGE = 6,
|
||||
NEO_TEXT_RED = 7
|
||||
};
|
||||
|
||||
// Event types returned by neoui_poll_event(timeout_ms)
|
||||
enum NeoEventType {
|
||||
NEO_EV_NONE = 0,
|
||||
NEO_EV_EXPOSE = 1,
|
||||
NEO_EV_KEY_PRESS = 2,
|
||||
NEO_EV_KEY_RELEASE = 3,
|
||||
NEO_EV_SOFTKEY_LEFT = 4,
|
||||
NEO_EV_SOFTKEY_RIGHT = 5,
|
||||
NEO_EV_SOFTKEY_CHORD = 6,
|
||||
NEO_EV_FIFO_CMD = 7,
|
||||
NEO_EV_THEME_RELOAD = 8,
|
||||
NEO_EV_CLOSE_REQ = 9
|
||||
};
|
||||
|
||||
// Logical keypad key codes returned by neoui_event_key()
|
||||
enum NeoKey {
|
||||
NEO_KEY_NONE = 0,
|
||||
NEO_KEY_UP = 1,
|
||||
NEO_KEY_DOWN = 2,
|
||||
NEO_KEY_LEFT = 3,
|
||||
NEO_KEY_RIGHT = 4,
|
||||
NEO_KEY_OK = 5,
|
||||
NEO_KEY_BACK = 6,
|
||||
NEO_KEY_CALL = 7,
|
||||
NEO_KEY_END = 8,
|
||||
NEO_KEY_SOFT_LEFT = 9,
|
||||
NEO_KEY_SOFT_RIGHT = 10,
|
||||
NEO_KEY_SPACE = 32,
|
||||
NEO_KEY_HASH = 35,
|
||||
NEO_KEY_STAR = 42,
|
||||
NEO_KEY_PLUS = 43,
|
||||
NEO_KEY_0 = 48,
|
||||
NEO_KEY_1 = 49,
|
||||
NEO_KEY_2 = 50,
|
||||
NEO_KEY_3 = 51,
|
||||
NEO_KEY_4 = 52,
|
||||
NEO_KEY_5 = 53,
|
||||
NEO_KEY_6 = 54,
|
||||
NEO_KEY_7 = 55,
|
||||
NEO_KEY_8 = 56,
|
||||
NEO_KEY_9 = 57
|
||||
};
|
||||
|
||||
// Multi-tap input modes
|
||||
enum NeoInputMode {
|
||||
NEO_INPUT_ABC_TITLE = 0,
|
||||
NEO_INPUT_ABC_LOWER = 1,
|
||||
NEO_INPUT_ABC_UPPER = 2,
|
||||
NEO_INPUT_123 = 3,
|
||||
NEO_INPUT_SYM = 4
|
||||
};
|
||||
|
||||
// Image scaling modes for neoui_draw_image_file
|
||||
enum NeoScaleMode {
|
||||
NEO_SCALE_FIT = 0,
|
||||
NEO_SCALE_FILL = 1,
|
||||
NEO_SCALE_STRETCH = 2
|
||||
};
|
||||
|
||||
// Opaque C context handle
|
||||
typedef struct NeoContext NeoContext;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. Window & Daemon Lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_init(const char* app_name, int preload_mode);
|
||||
int neoui_init_ex(const char* app_name, const char* res_name,
|
||||
const char* res_class, const char* win_title,
|
||||
int x, int y, int w, int h,
|
||||
int override_redirect, int preload_mode);
|
||||
int neoui_shutdown(void);
|
||||
|
||||
int neoui_show(void);
|
||||
int neoui_hide(void);
|
||||
int neoui_is_visible(void);
|
||||
int neoui_raise_and_grab(void);
|
||||
int neoui_ungrab(void);
|
||||
|
||||
int neoui_width(void);
|
||||
int neoui_height(void);
|
||||
|
||||
int neoui_begin_frame(void);
|
||||
int neoui_end_frame(void);
|
||||
int neoui_flush(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 2. Unified .Xresources / .xth Theme & Icon Resolution
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_reload_theme(void);
|
||||
int neoui_check_reload_theme(void);
|
||||
int neoui_apply_theme_file(const char* xth_path);
|
||||
int neoui_broadcast_theme_reload(const char* skip_plugin);
|
||||
|
||||
const char* neoui_theme_name(void);
|
||||
const char* neoui_font_face(void);
|
||||
const char* neoui_icon_font_face(void);
|
||||
int neoui_base_font_size(void);
|
||||
int neoui_font_size(int font_role);
|
||||
|
||||
uint32_t neoui_color(int color_id);
|
||||
uint32_t neoui_adjust_rgb(uint32_t rgb, int delta);
|
||||
uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct);
|
||||
uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb);
|
||||
const char* neoui_format_hex_rgb(uint32_t rgb);
|
||||
const char* neoui_icon(const char* icon_name);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 3. Drawing Primitives & Text Rendering
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_clear(uint32_t rgb);
|
||||
int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb);
|
||||
int neoui_set_clip(int x, int y, int w, int h);
|
||||
int neoui_reset_clip(void);
|
||||
|
||||
int neoui_draw_text(int font_role, int color_role, int x, int y, int h,
|
||||
const char* text, int max_w);
|
||||
int neoui_draw_text_centered(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text);
|
||||
int neoui_draw_text_right(int font_role, int color_role, int right_x, int y,
|
||||
int h, const char* text, int max_w);
|
||||
int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text, int scroll_line);
|
||||
int neoui_text_width(int font_role, const char* text);
|
||||
const char* neoui_tail_fit_text(int font_role, const char* text, int max_w);
|
||||
|
||||
int neoui_draw_image_file(const char* path, int x, int y, int w, int h,
|
||||
int scale_mode);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 4. Standardized OS Shell UI Components (Widgets)
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_draw_header(const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* right_badge);
|
||||
int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role,
|
||||
const char* title, int title_color_role,
|
||||
const char* right_badge, int right_color_role);
|
||||
|
||||
int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h);
|
||||
|
||||
int neoui_draw_softkeys(const char* left_label, const char* center_label,
|
||||
const char* right_label);
|
||||
int neoui_draw_softkeys_ex(const char* left_label, const char* center_label,
|
||||
const char* right_label, int center_color_role);
|
||||
|
||||
int neoui_draw_list_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* subtitle,
|
||||
const char* right_text);
|
||||
|
||||
int neoui_draw_slider_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int pct, const char* value_text);
|
||||
|
||||
int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int is_on,
|
||||
const char* state_text);
|
||||
|
||||
int neoui_draw_button(int x, int y, int w, int h, int is_selected,
|
||||
int is_danger, const char* icon_str, const char* label);
|
||||
|
||||
int neoui_draw_input_box(int x, int y, int w, int h, int is_focused,
|
||||
const char* label, const char* value,
|
||||
const char* placeholder, int password_mask);
|
||||
|
||||
int neoui_draw_progress_bar(int x, int y, int w, int h, int pct,
|
||||
uint32_t fill_rgb);
|
||||
|
||||
int neoui_draw_scrollbar(int x, int y, int h, int total_items,
|
||||
int visible_items, int scroll_offset);
|
||||
|
||||
int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str,
|
||||
int icon_color_role, const char* title);
|
||||
|
||||
int neoui_draw_confirm_dialog(const char* title, const char* line1,
|
||||
const char* line2, const char* no_label,
|
||||
const char* yes_label, int selected_yes);
|
||||
|
||||
int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons,
|
||||
int selected_idx, int max_visible_rows);
|
||||
|
||||
int neoui_draw_toast(const char* message);
|
||||
int neoui_show_toast(const char* message, int duration_ms);
|
||||
int neoui_clear_toast(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 5. Event Loop, Keypad & Multi-Tap Input Management
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_poll_event(int timeout_ms);
|
||||
int neoui_event_key(void);
|
||||
int neoui_event_keycode(void);
|
||||
int neoui_event_keysym(void);
|
||||
const char* neoui_event_command(void);
|
||||
int neoui_set_chord_xdrawer(int enabled);
|
||||
|
||||
int neoui_input_reset(const char* initial_text);
|
||||
int neoui_input_set_text(const char* text);
|
||||
const char* neoui_input_get_text(void);
|
||||
int neoui_input_set_mode(int mode);
|
||||
int neoui_input_get_mode(void);
|
||||
int neoui_input_cycle_mode(void);
|
||||
const char* neoui_input_mode_badge(void);
|
||||
int neoui_input_feed_key(int neo_key);
|
||||
int neoui_input_commit_tap(void);
|
||||
int neoui_input_backspace(void);
|
||||
int neoui_input_is_tap_active(void);
|
||||
const char* neoui_input_candidate_bar(const char* idle_hint);
|
||||
int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 6. System & IPC Utilities
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd);
|
||||
int neoui_vibrate(int duration_ms);
|
||||
int neoui_now_ms(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
namespace bananarchy {
|
||||
|
||||
std::string themeTrim(const std::string& s);
|
||||
int themeHexNibble(char c);
|
||||
bool parseHexRgb(const std::string& raw, uint32_t* outRgb);
|
||||
std::string formatHexRgb(uint32_t rgb);
|
||||
uint32_t adjustRgb(uint32_t rgb, int delta);
|
||||
uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct);
|
||||
std::string getHomeDirPath();
|
||||
std::string getXresourcesPath();
|
||||
std::string getThemesDirPath();
|
||||
|
||||
struct ThemeSpec {
|
||||
std::string name = "Default";
|
||||
std::string fontFace = "Fira Code";
|
||||
std::string iconFontFace = "DejaVuSansM Nerd Font";
|
||||
int baseFontSize = 15;
|
||||
|
||||
uint32_t bgMain = 0x222222;
|
||||
uint32_t bgBar = 0x222222;
|
||||
uint32_t bgHeader = 0x1c1c1c;
|
||||
uint32_t bgFooter = 0x181818;
|
||||
uint32_t bgOverlay = 0x161616;
|
||||
uint32_t bgAltEven = 0x282828;
|
||||
uint32_t bgAltOdd = 0x2e2e2e;
|
||||
uint32_t bgInput = 0x1a1a1a;
|
||||
uint32_t bgInputFocus = 0x1b3b4b;
|
||||
uint32_t bgButton = 0x2a2a2a;
|
||||
uint32_t bgSearch = 0x383838;
|
||||
uint32_t bgBubbleIn = 0x262d32;
|
||||
uint32_t bgBubbleOut = 0x1f2d38;
|
||||
uint32_t bgToast = 0x102535;
|
||||
|
||||
uint32_t fgMain = 0xdddddd;
|
||||
uint32_t fgBright = 0xffffff;
|
||||
uint32_t fgMuted = 0x999999;
|
||||
|
||||
uint32_t selBg = 0x005577;
|
||||
uint32_t selFg = 0xffffff;
|
||||
uint32_t accent = 0xf4d03f;
|
||||
uint32_t accentAlt = 0x0088bb;
|
||||
uint32_t highlight = 0xffc978;
|
||||
uint32_t border = 0x444444;
|
||||
uint32_t divider = 0x666666;
|
||||
|
||||
uint32_t success = 0x2ecc71;
|
||||
uint32_t info = 0x5dade2;
|
||||
uint32_t warning = 0xe67e22;
|
||||
uint32_t danger = 0xe74c3c;
|
||||
uint32_t dangerBg = 0x922b21;
|
||||
|
||||
int sizeSmall() const;
|
||||
int sizeMain() const;
|
||||
int sizeIcon() const;
|
||||
int sizeLarge() const;
|
||||
|
||||
std::string pangoMainFontStr() const;
|
||||
std::string pangoSmallFontStr() const;
|
||||
std::string pangoIconFontStr() const;
|
||||
std::string pangoLargeBoldFontStr() const;
|
||||
std::string xftFontStr(int pxSize) const;
|
||||
std::string xftIconFontStr(int pxSize) const;
|
||||
|
||||
void recomputeDerivedFromCore();
|
||||
void parseFromMap(const std::unordered_map<std::string, std::string>& kv);
|
||||
static void parseLinesIntoMap(
|
||||
const std::string& content,
|
||||
std::unordered_map<std::string, std::string>& kv);
|
||||
bool loadFromFile(const std::string& path);
|
||||
void loadActive(Display* dpy, int screen);
|
||||
std::string serializeXresources() const;
|
||||
bool saveToFile(const std::string& path) const;
|
||||
uint32_t colorById(int colorId) const;
|
||||
};
|
||||
|
||||
ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0);
|
||||
|
||||
struct PluginTheme {
|
||||
ThemeSpec spec;
|
||||
time_t lastXresMtime = -1;
|
||||
off_t lastXresSize = -1;
|
||||
bool colorsAllocated = false;
|
||||
|
||||
Display* dpy_ = nullptr;
|
||||
int screen_ = 0;
|
||||
Visual* visual_ = nullptr;
|
||||
Colormap cmap_ = 0;
|
||||
Window win_ = None;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
|
||||
XftColor colWhite{};
|
||||
XftColor colLight{};
|
||||
XftColor colMuted{};
|
||||
XftColor colYellow{};
|
||||
XftColor colGreen{};
|
||||
XftColor colBlue{};
|
||||
XftColor colOrange{};
|
||||
XftColor colRed{};
|
||||
|
||||
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
|
||||
XftColor* dst);
|
||||
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
Window win = None);
|
||||
void reload();
|
||||
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr, PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr, PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
bool checkAndReload();
|
||||
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr,
|
||||
PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr,
|
||||
PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
XftColor* colorByRole(int role);
|
||||
PangoLayout* layoutByRole(int role);
|
||||
};
|
||||
|
||||
// Shared Pango rendering & layout helpers in libneoui.so
|
||||
int neoDrawPango(XftDraw* xftDraw, PangoLayout* layout, XftColor* color,
|
||||
int x, int y, int h, const std::string& text,
|
||||
int maxW = -1, int align = 0);
|
||||
int neoPangoWidth(PangoLayout* layout, const std::string& text);
|
||||
void neoDrawSoftbar(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel,
|
||||
XftColor* centerCol = nullptr);
|
||||
void neoDrawScrollbar(Display* dpy, Pixmap pix, GC gc, const PluginTheme& theme,
|
||||
int x, int y, int h, int totalItems, int visibleItems,
|
||||
int scrollOffset);
|
||||
void neoDrawToast(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& msg);
|
||||
|
||||
std::string formatMultiTapBar(const std::string& prefix, const char* table,
|
||||
int activeIdx, bool makeUpper, int maxItems = 7,
|
||||
size_t maxChars = 21);
|
||||
std::string tailFitPangoText(PangoLayout* layout, const std::string& text,
|
||||
int maxWidthPx);
|
||||
|
||||
// Shared image & media helpers in libneoui.so
|
||||
bool saveRgb24AsJpeg(const std::string& path, const uint8_t* rgb, int width,
|
||||
int height, int quality = 92);
|
||||
bool loadJpegRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadPngRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadFfmpegImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb, int srcW, int srcH,
|
||||
uint32_t* dstBgrx, int canvasW, int canvasH,
|
||||
uint32_t bgPixel = 0x111111,
|
||||
int scaleMode = NEO_SCALE_FIT);
|
||||
void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
|
||||
uint32_t* dstBgrx,
|
||||
int zoomFactor = 1);
|
||||
std::string formatFileSize(off_t bytes);
|
||||
|
||||
// High-level C++ RAII Window + Theme + Offscreen Pixmap + Pango Context
|
||||
class NeoWindow {
|
||||
public:
|
||||
Display* dpy = nullptr;
|
||||
int screen = 0;
|
||||
Window root = None;
|
||||
Visual* visual = nullptr;
|
||||
Colormap cmap = 0;
|
||||
Window win = None;
|
||||
Pixmap pix = None;
|
||||
GC gc = nullptr;
|
||||
XftDraw* xftDraw = nullptr;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
PluginTheme theme;
|
||||
int x = NEO_WIN_X;
|
||||
int y = NEO_WIN_Y;
|
||||
int width = NEO_WIN_W;
|
||||
int height = NEO_WIN_H;
|
||||
|
||||
NeoWindow() = default;
|
||||
~NeoWindow();
|
||||
|
||||
NeoWindow(const NeoWindow&) = delete;
|
||||
NeoWindow& operator=(const NeoWindow&) = delete;
|
||||
|
||||
bool create(const char* resName, const char* resClass, const char* title,
|
||||
int winX = NEO_WIN_X, int winY = NEO_WIN_Y,
|
||||
int winW = NEO_WIN_W, int winH = NEO_WIN_H,
|
||||
bool overrideRedirect = true,
|
||||
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
ButtonPressMask | VisibilityChangeMask |
|
||||
StructureNotifyMask);
|
||||
void destroy();
|
||||
|
||||
void bindAsActiveContext();
|
||||
|
||||
int drawPango(PangoLayout* layout, XftColor* color, int px, int py, int ph,
|
||||
const std::string& text, int maxW = -1, int align = 0) {
|
||||
return neoDrawPango(xftDraw, layout, color, px, py, ph, text, maxW, align);
|
||||
}
|
||||
|
||||
int pangoWidth(PangoLayout* layout, const std::string& text) {
|
||||
return neoPangoWidth(layout, text);
|
||||
}
|
||||
|
||||
void drawSoftbar(const std::string& leftLabel, const std::string& centerLabel,
|
||||
const std::string& rightLabel, XftColor* centerCol = nullptr,
|
||||
int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawSoftbar(dpy, pix, gc, xftDraw, theme, width, height, softbarH,
|
||||
leftLabel, centerLabel, rightLabel, centerCol);
|
||||
}
|
||||
|
||||
void drawScrollbar(int sx, int sy, int sh, int totalItems, int visibleItems,
|
||||
int scrollOffset) {
|
||||
neoDrawScrollbar(dpy, pix, gc, theme, sx, sy, sh, totalItems, visibleItems,
|
||||
scrollOffset);
|
||||
}
|
||||
|
||||
void drawToast(const std::string& msg, int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawToast(dpy, pix, gc, xftDraw, theme, width, height, softbarH, msg);
|
||||
}
|
||||
|
||||
void clearBg() {
|
||||
if (dpy && pix != None && gc) {
|
||||
XSetForeground(dpy, gc, theme.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void present() {
|
||||
if (dpy && pix != None && win != None && gc) {
|
||||
XCopyArea(dpy, pix, win, gc, 0, 0, width, height, 0, 0);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkReloadTheme() {
|
||||
return theme.checkAndReload(dpy, screen, visual, cmap, layoutMain,
|
||||
layoutSmall, layoutIcon, layoutNum, win);
|
||||
}
|
||||
|
||||
void reloadTheme() {
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace bananarchy
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // BANANARCHY_NEOUI_H
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Symlink
+1
@@ -0,0 +1 @@
|
||||
/home/user/Projects/neoui.yab
|
||||
@@ -0,0 +1,575 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// NeoUI - Bananarchy 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
|
||||
// Provides both a C-compatible FFI (libneoui.so) and C++20 SDK classes.
|
||||
// Note: Every extern "C" function returns int, uint32_t, or const char* (never
|
||||
// void) so that FFI callers such as Yabasic frnfn_call / frnfn_call$ work
|
||||
// directly without void-return limitations.
|
||||
|
||||
#ifndef BANANARCHY_NEOUI_H
|
||||
#define BANANARCHY_NEOUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Standard Bananarchy 240x320 QVGA geometry constants
|
||||
enum NeoGeometry {
|
||||
NEO_SCREEN_W = 240,
|
||||
NEO_SCREEN_H = 320,
|
||||
NEO_TOPBAR_H = 24,
|
||||
NEO_WIN_X = 0,
|
||||
NEO_WIN_Y = 24,
|
||||
NEO_WIN_W = 240,
|
||||
NEO_WIN_H = 296,
|
||||
NEO_HEADER_H = 34,
|
||||
NEO_SOFTBAR_H = 26
|
||||
};
|
||||
|
||||
// Theme color token IDs for neoui_color(color_id)
|
||||
enum NeoColorId {
|
||||
NEO_COLOR_BG_MAIN = 0,
|
||||
NEO_COLOR_BG_BAR = 1,
|
||||
NEO_COLOR_BG_HEADER = 2,
|
||||
NEO_COLOR_BG_FOOTER = 3,
|
||||
NEO_COLOR_BG_OVERLAY = 4,
|
||||
NEO_COLOR_BG_ALT_EVEN = 5,
|
||||
NEO_COLOR_BG_ALT_ODD = 6,
|
||||
NEO_COLOR_BG_INPUT = 7,
|
||||
NEO_COLOR_BG_INPUT_FOCUS = 8,
|
||||
NEO_COLOR_BG_BUTTON = 9,
|
||||
NEO_COLOR_BG_SEARCH = 10,
|
||||
NEO_COLOR_BG_BUBBLE_IN = 11,
|
||||
NEO_COLOR_BG_BUBBLE_OUT = 12,
|
||||
NEO_COLOR_BG_TOAST = 13,
|
||||
NEO_COLOR_FG_MAIN = 14,
|
||||
NEO_COLOR_FG_BRIGHT = 15,
|
||||
NEO_COLOR_FG_MUTED = 16,
|
||||
NEO_COLOR_SEL_BG = 17,
|
||||
NEO_COLOR_SEL_FG = 18,
|
||||
NEO_COLOR_ACCENT = 19,
|
||||
NEO_COLOR_ACCENT_ALT = 20,
|
||||
NEO_COLOR_HIGHLIGHT = 21,
|
||||
NEO_COLOR_BORDER = 22,
|
||||
NEO_COLOR_DIVIDER = 23,
|
||||
NEO_COLOR_SUCCESS = 24,
|
||||
NEO_COLOR_INFO = 25,
|
||||
NEO_COLOR_WARNING = 26,
|
||||
NEO_COLOR_DANGER = 27,
|
||||
NEO_COLOR_DANGER_BG = 28
|
||||
};
|
||||
|
||||
// Proportional Pango font roles
|
||||
enum NeoFontRole {
|
||||
NEO_FONT_SMALL = 0,
|
||||
NEO_FONT_MAIN = 1,
|
||||
NEO_FONT_ICON = 2,
|
||||
NEO_FONT_LARGE = 3
|
||||
};
|
||||
|
||||
// Semantic Xft text color roles
|
||||
enum NeoTextColor {
|
||||
NEO_TEXT_WHITE = 0,
|
||||
NEO_TEXT_LIGHT = 1,
|
||||
NEO_TEXT_MUTED = 2,
|
||||
NEO_TEXT_YELLOW = 3,
|
||||
NEO_TEXT_GREEN = 4,
|
||||
NEO_TEXT_BLUE = 5,
|
||||
NEO_TEXT_ORANGE = 6,
|
||||
NEO_TEXT_RED = 7
|
||||
};
|
||||
|
||||
// Event types returned by neoui_poll_event(timeout_ms)
|
||||
enum NeoEventType {
|
||||
NEO_EV_NONE = 0,
|
||||
NEO_EV_EXPOSE = 1,
|
||||
NEO_EV_KEY_PRESS = 2,
|
||||
NEO_EV_KEY_RELEASE = 3,
|
||||
NEO_EV_SOFTKEY_LEFT = 4,
|
||||
NEO_EV_SOFTKEY_RIGHT = 5,
|
||||
NEO_EV_SOFTKEY_CHORD = 6,
|
||||
NEO_EV_FIFO_CMD = 7,
|
||||
NEO_EV_THEME_RELOAD = 8,
|
||||
NEO_EV_CLOSE_REQ = 9
|
||||
};
|
||||
|
||||
// Logical keypad key codes returned by neoui_event_key()
|
||||
enum NeoKey {
|
||||
NEO_KEY_NONE = 0,
|
||||
NEO_KEY_UP = 1,
|
||||
NEO_KEY_DOWN = 2,
|
||||
NEO_KEY_LEFT = 3,
|
||||
NEO_KEY_RIGHT = 4,
|
||||
NEO_KEY_OK = 5,
|
||||
NEO_KEY_BACK = 6,
|
||||
NEO_KEY_CALL = 7,
|
||||
NEO_KEY_END = 8,
|
||||
NEO_KEY_SOFT_LEFT = 9,
|
||||
NEO_KEY_SOFT_RIGHT = 10,
|
||||
NEO_KEY_SPACE = 32,
|
||||
NEO_KEY_HASH = 35,
|
||||
NEO_KEY_STAR = 42,
|
||||
NEO_KEY_PLUS = 43,
|
||||
NEO_KEY_0 = 48,
|
||||
NEO_KEY_1 = 49,
|
||||
NEO_KEY_2 = 50,
|
||||
NEO_KEY_3 = 51,
|
||||
NEO_KEY_4 = 52,
|
||||
NEO_KEY_5 = 53,
|
||||
NEO_KEY_6 = 54,
|
||||
NEO_KEY_7 = 55,
|
||||
NEO_KEY_8 = 56,
|
||||
NEO_KEY_9 = 57
|
||||
};
|
||||
|
||||
// Multi-tap input modes
|
||||
enum NeoInputMode {
|
||||
NEO_INPUT_ABC_TITLE = 0,
|
||||
NEO_INPUT_ABC_LOWER = 1,
|
||||
NEO_INPUT_ABC_UPPER = 2,
|
||||
NEO_INPUT_123 = 3,
|
||||
NEO_INPUT_SYM = 4
|
||||
};
|
||||
|
||||
// Image scaling modes for neoui_draw_image_file
|
||||
enum NeoScaleMode {
|
||||
NEO_SCALE_FIT = 0,
|
||||
NEO_SCALE_FILL = 1,
|
||||
NEO_SCALE_STRETCH = 2
|
||||
};
|
||||
|
||||
// Opaque C context handle
|
||||
typedef struct NeoContext NeoContext;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. Window & Daemon Lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_init(const char* app_name, int preload_mode);
|
||||
int neoui_init_ex(const char* app_name, const char* res_name,
|
||||
const char* res_class, const char* win_title,
|
||||
int x, int y, int w, int h,
|
||||
int override_redirect, int preload_mode);
|
||||
int neoui_shutdown(void);
|
||||
|
||||
int neoui_show(void);
|
||||
int neoui_hide(void);
|
||||
int neoui_is_visible(void);
|
||||
int neoui_raise_and_grab(void);
|
||||
int neoui_ungrab(void);
|
||||
|
||||
int neoui_width(void);
|
||||
int neoui_height(void);
|
||||
|
||||
int neoui_begin_frame(void);
|
||||
int neoui_end_frame(void);
|
||||
int neoui_flush(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 2. Unified .Xresources / .xth Theme & Icon Resolution
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_reload_theme(void);
|
||||
int neoui_check_reload_theme(void);
|
||||
int neoui_apply_theme_file(const char* xth_path);
|
||||
int neoui_broadcast_theme_reload(const char* skip_plugin);
|
||||
|
||||
const char* neoui_theme_name(void);
|
||||
const char* neoui_font_face(void);
|
||||
const char* neoui_icon_font_face(void);
|
||||
int neoui_base_font_size(void);
|
||||
int neoui_font_size(int font_role);
|
||||
|
||||
uint32_t neoui_color(int color_id);
|
||||
uint32_t neoui_adjust_rgb(uint32_t rgb, int delta);
|
||||
uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct);
|
||||
uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb);
|
||||
const char* neoui_format_hex_rgb(uint32_t rgb);
|
||||
const char* neoui_icon(const char* icon_name);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 3. Drawing Primitives & Text Rendering
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_clear(uint32_t rgb);
|
||||
int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb);
|
||||
int neoui_set_clip(int x, int y, int w, int h);
|
||||
int neoui_reset_clip(void);
|
||||
|
||||
int neoui_draw_text(int font_role, int color_role, int x, int y, int h,
|
||||
const char* text, int max_w);
|
||||
int neoui_draw_text_centered(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text);
|
||||
int neoui_draw_text_right(int font_role, int color_role, int right_x, int y,
|
||||
int h, const char* text, int max_w);
|
||||
int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text, int scroll_line);
|
||||
int neoui_text_width(int font_role, const char* text);
|
||||
const char* neoui_tail_fit_text(int font_role, const char* text, int max_w);
|
||||
|
||||
int neoui_draw_image_file(const char* path, int x, int y, int w, int h,
|
||||
int scale_mode);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 4. Standardized OS Shell UI Components (Widgets)
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_draw_header(const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* right_badge);
|
||||
int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role,
|
||||
const char* title, int title_color_role,
|
||||
const char* right_badge, int right_color_role);
|
||||
|
||||
int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h);
|
||||
|
||||
int neoui_draw_softkeys(const char* left_label, const char* center_label,
|
||||
const char* right_label);
|
||||
int neoui_draw_softkeys_ex(const char* left_label, const char* center_label,
|
||||
const char* right_label, int center_color_role);
|
||||
|
||||
int neoui_draw_list_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* subtitle,
|
||||
const char* right_text);
|
||||
|
||||
int neoui_draw_slider_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int pct, const char* value_text);
|
||||
|
||||
int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int is_on,
|
||||
const char* state_text);
|
||||
|
||||
int neoui_draw_button(int x, int y, int w, int h, int is_selected,
|
||||
int is_danger, const char* icon_str, const char* label);
|
||||
|
||||
int neoui_draw_input_box(int x, int y, int w, int h, int is_focused,
|
||||
const char* label, const char* value,
|
||||
const char* placeholder, int password_mask);
|
||||
|
||||
int neoui_draw_progress_bar(int x, int y, int w, int h, int pct,
|
||||
uint32_t fill_rgb);
|
||||
|
||||
int neoui_draw_scrollbar(int x, int y, int h, int total_items,
|
||||
int visible_items, int scroll_offset);
|
||||
|
||||
int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str,
|
||||
int icon_color_role, const char* title);
|
||||
|
||||
int neoui_draw_confirm_dialog(const char* title, const char* line1,
|
||||
const char* line2, const char* no_label,
|
||||
const char* yes_label, int selected_yes);
|
||||
|
||||
int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons,
|
||||
int selected_idx, int max_visible_rows);
|
||||
|
||||
int neoui_draw_toast(const char* message);
|
||||
int neoui_show_toast(const char* message, int duration_ms);
|
||||
int neoui_clear_toast(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 5. Event Loop, Keypad & Multi-Tap Input Management
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_poll_event(int timeout_ms);
|
||||
int neoui_event_key(void);
|
||||
int neoui_event_keycode(void);
|
||||
int neoui_event_keysym(void);
|
||||
const char* neoui_event_command(void);
|
||||
int neoui_set_chord_xdrawer(int enabled);
|
||||
|
||||
int neoui_input_reset(const char* initial_text);
|
||||
int neoui_input_set_text(const char* text);
|
||||
const char* neoui_input_get_text(void);
|
||||
int neoui_input_set_mode(int mode);
|
||||
int neoui_input_get_mode(void);
|
||||
int neoui_input_cycle_mode(void);
|
||||
const char* neoui_input_mode_badge(void);
|
||||
int neoui_input_feed_key(int neo_key);
|
||||
int neoui_input_commit_tap(void);
|
||||
int neoui_input_backspace(void);
|
||||
int neoui_input_is_tap_active(void);
|
||||
const char* neoui_input_candidate_bar(const char* idle_hint);
|
||||
int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 6. System & IPC Utilities
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd);
|
||||
int neoui_vibrate(int duration_ms);
|
||||
int neoui_now_ms(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
namespace bananarchy {
|
||||
|
||||
std::string themeTrim(const std::string& s);
|
||||
int themeHexNibble(char c);
|
||||
bool parseHexRgb(const std::string& raw, uint32_t* outRgb);
|
||||
std::string formatHexRgb(uint32_t rgb);
|
||||
uint32_t adjustRgb(uint32_t rgb, int delta);
|
||||
uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct);
|
||||
std::string getHomeDirPath();
|
||||
std::string getXresourcesPath();
|
||||
std::string getThemesDirPath();
|
||||
|
||||
struct ThemeSpec {
|
||||
std::string name = "Default";
|
||||
std::string fontFace = "Fira Code";
|
||||
std::string iconFontFace = "DejaVuSansM Nerd Font";
|
||||
int baseFontSize = 15;
|
||||
|
||||
uint32_t bgMain = 0x222222;
|
||||
uint32_t bgBar = 0x222222;
|
||||
uint32_t bgHeader = 0x1c1c1c;
|
||||
uint32_t bgFooter = 0x181818;
|
||||
uint32_t bgOverlay = 0x161616;
|
||||
uint32_t bgAltEven = 0x282828;
|
||||
uint32_t bgAltOdd = 0x2e2e2e;
|
||||
uint32_t bgInput = 0x1a1a1a;
|
||||
uint32_t bgInputFocus = 0x1b3b4b;
|
||||
uint32_t bgButton = 0x2a2a2a;
|
||||
uint32_t bgSearch = 0x383838;
|
||||
uint32_t bgBubbleIn = 0x262d32;
|
||||
uint32_t bgBubbleOut = 0x1f2d38;
|
||||
uint32_t bgToast = 0x102535;
|
||||
|
||||
uint32_t fgMain = 0xdddddd;
|
||||
uint32_t fgBright = 0xffffff;
|
||||
uint32_t fgMuted = 0x999999;
|
||||
|
||||
uint32_t selBg = 0x005577;
|
||||
uint32_t selFg = 0xffffff;
|
||||
uint32_t accent = 0xf4d03f;
|
||||
uint32_t accentAlt = 0x0088bb;
|
||||
uint32_t highlight = 0xffc978;
|
||||
uint32_t border = 0x444444;
|
||||
uint32_t divider = 0x666666;
|
||||
|
||||
uint32_t success = 0x2ecc71;
|
||||
uint32_t info = 0x5dade2;
|
||||
uint32_t warning = 0xe67e22;
|
||||
uint32_t danger = 0xe74c3c;
|
||||
uint32_t dangerBg = 0x922b21;
|
||||
|
||||
int sizeSmall() const;
|
||||
int sizeMain() const;
|
||||
int sizeIcon() const;
|
||||
int sizeLarge() const;
|
||||
|
||||
std::string pangoMainFontStr() const;
|
||||
std::string pangoSmallFontStr() const;
|
||||
std::string pangoIconFontStr() const;
|
||||
std::string pangoLargeBoldFontStr() const;
|
||||
std::string xftFontStr(int pxSize) const;
|
||||
std::string xftIconFontStr(int pxSize) const;
|
||||
|
||||
void recomputeDerivedFromCore();
|
||||
void parseFromMap(const std::unordered_map<std::string, std::string>& kv);
|
||||
static void parseLinesIntoMap(
|
||||
const std::string& content,
|
||||
std::unordered_map<std::string, std::string>& kv);
|
||||
bool loadFromFile(const std::string& path);
|
||||
void loadActive(Display* dpy, int screen);
|
||||
std::string serializeXresources() const;
|
||||
bool saveToFile(const std::string& path) const;
|
||||
uint32_t colorById(int colorId) const;
|
||||
};
|
||||
|
||||
ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0);
|
||||
|
||||
struct PluginTheme {
|
||||
ThemeSpec spec;
|
||||
time_t lastXresMtime = -1;
|
||||
off_t lastXresSize = -1;
|
||||
bool colorsAllocated = false;
|
||||
|
||||
Display* dpy_ = nullptr;
|
||||
int screen_ = 0;
|
||||
Visual* visual_ = nullptr;
|
||||
Colormap cmap_ = 0;
|
||||
Window win_ = None;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
|
||||
XftColor colWhite{};
|
||||
XftColor colLight{};
|
||||
XftColor colMuted{};
|
||||
XftColor colYellow{};
|
||||
XftColor colGreen{};
|
||||
XftColor colBlue{};
|
||||
XftColor colOrange{};
|
||||
XftColor colRed{};
|
||||
|
||||
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
|
||||
XftColor* dst);
|
||||
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
Window win = None);
|
||||
void reload();
|
||||
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr, PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr, PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
bool checkAndReload();
|
||||
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr,
|
||||
PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr,
|
||||
PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
XftColor* colorByRole(int role);
|
||||
PangoLayout* layoutByRole(int role);
|
||||
};
|
||||
|
||||
// Shared Pango rendering & layout helpers in libneoui.so
|
||||
int neoDrawPango(XftDraw* xftDraw, PangoLayout* layout, XftColor* color,
|
||||
int x, int y, int h, const std::string& text,
|
||||
int maxW = -1, int align = 0);
|
||||
int neoPangoWidth(PangoLayout* layout, const std::string& text);
|
||||
void neoDrawSoftbar(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel,
|
||||
XftColor* centerCol = nullptr);
|
||||
void neoDrawScrollbar(Display* dpy, Pixmap pix, GC gc, const PluginTheme& theme,
|
||||
int x, int y, int h, int totalItems, int visibleItems,
|
||||
int scrollOffset);
|
||||
void neoDrawToast(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& msg);
|
||||
|
||||
std::string formatMultiTapBar(const std::string& prefix, const char* table,
|
||||
int activeIdx, bool makeUpper, int maxItems = 7,
|
||||
size_t maxChars = 21);
|
||||
std::string tailFitPangoText(PangoLayout* layout, const std::string& text,
|
||||
int maxWidthPx);
|
||||
|
||||
// Shared image & media helpers in libneoui.so
|
||||
bool saveRgb24AsJpeg(const std::string& path, const uint8_t* rgb, int width,
|
||||
int height, int quality = 92);
|
||||
bool loadJpegRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadPngRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadFfmpegImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb, int srcW, int srcH,
|
||||
uint32_t* dstBgrx, int canvasW, int canvasH,
|
||||
uint32_t bgPixel = 0x111111,
|
||||
int scaleMode = NEO_SCALE_FIT);
|
||||
void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
|
||||
uint32_t* dstBgrx,
|
||||
int zoomFactor = 1);
|
||||
std::string formatFileSize(off_t bytes);
|
||||
|
||||
// High-level C++ RAII Window + Theme + Offscreen Pixmap + Pango Context
|
||||
class NeoWindow {
|
||||
public:
|
||||
Display* dpy = nullptr;
|
||||
int screen = 0;
|
||||
Window root = None;
|
||||
Visual* visual = nullptr;
|
||||
Colormap cmap = 0;
|
||||
Window win = None;
|
||||
Pixmap pix = None;
|
||||
GC gc = nullptr;
|
||||
XftDraw* xftDraw = nullptr;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
PluginTheme theme;
|
||||
int x = NEO_WIN_X;
|
||||
int y = NEO_WIN_Y;
|
||||
int width = NEO_WIN_W;
|
||||
int height = NEO_WIN_H;
|
||||
|
||||
NeoWindow() = default;
|
||||
~NeoWindow();
|
||||
|
||||
NeoWindow(const NeoWindow&) = delete;
|
||||
NeoWindow& operator=(const NeoWindow&) = delete;
|
||||
|
||||
bool create(const char* resName, const char* resClass, const char* title,
|
||||
int winX = NEO_WIN_X, int winY = NEO_WIN_Y,
|
||||
int winW = NEO_WIN_W, int winH = NEO_WIN_H,
|
||||
bool overrideRedirect = true,
|
||||
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
ButtonPressMask | VisibilityChangeMask |
|
||||
StructureNotifyMask);
|
||||
void destroy();
|
||||
|
||||
void bindAsActiveContext();
|
||||
|
||||
int drawPango(PangoLayout* layout, XftColor* color, int px, int py, int ph,
|
||||
const std::string& text, int maxW = -1, int align = 0) {
|
||||
return neoDrawPango(xftDraw, layout, color, px, py, ph, text, maxW, align);
|
||||
}
|
||||
|
||||
int pangoWidth(PangoLayout* layout, const std::string& text) {
|
||||
return neoPangoWidth(layout, text);
|
||||
}
|
||||
|
||||
void drawSoftbar(const std::string& leftLabel, const std::string& centerLabel,
|
||||
const std::string& rightLabel, XftColor* centerCol = nullptr,
|
||||
int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawSoftbar(dpy, pix, gc, xftDraw, theme, width, height, softbarH,
|
||||
leftLabel, centerLabel, rightLabel, centerCol);
|
||||
}
|
||||
|
||||
void drawScrollbar(int sx, int sy, int sh, int totalItems, int visibleItems,
|
||||
int scrollOffset) {
|
||||
neoDrawScrollbar(dpy, pix, gc, theme, sx, sy, sh, totalItems, visibleItems,
|
||||
scrollOffset);
|
||||
}
|
||||
|
||||
void drawToast(const std::string& msg, int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawToast(dpy, pix, gc, xftDraw, theme, width, height, softbarH, msg);
|
||||
}
|
||||
|
||||
void clearBg() {
|
||||
if (dpy && pix != None && gc) {
|
||||
XSetForeground(dpy, gc, theme.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void present() {
|
||||
if (dpy && pix != None && win != None && gc) {
|
||||
XCopyArea(dpy, pix, win, gc, 0, 0, width, height, 0, 0);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkReloadTheme() {
|
||||
return theme.checkAndReload(dpy, screen, visual, cmap, layoutMain,
|
||||
layoutSmall, layoutIcon, layoutNum, win);
|
||||
}
|
||||
|
||||
void reloadTheme() {
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace bananarchy
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // BANANARCHY_NEOUI_H
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
+39
-19
@@ -100,69 +100,81 @@ EOF
|
||||
dwm.c drw.c util.c $DWM_LIBS -o /bananarchy/prebuilt/sxmo-x11/usr/bin/dwm
|
||||
$STRIP --strip-unneeded /bananarchy/prebuilt/sxmo-x11/usr/bin/dwm
|
||||
|
||||
echo "[6/6] Compiling DWM Plugins (xdrawer, dialer, calllog, callscreen, contacts, sms, files, camera, themes) and dwm-plugin runner..."
|
||||
mkdir -p /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins
|
||||
PLUG_INCS="$(pkgconf --cflags x11 xft fontconfig freetype2 pango pangoxft alsa libjpeg libpng)"
|
||||
echo "[6/7] Compiling NeoUI SDK shared library (libneoui.so + /usr/include/neoui.h)..."
|
||||
mkdir -p /bananarchy/prebuilt/sxmo-x11/usr/lib /bananarchy/prebuilt/sxmo-x11/usr/include
|
||||
PLUG_INCS="$(pkgconf --cflags x11 xft fontconfig freetype2 pango pangoxft alsa libjpeg libpng) -I/bananarchy/src/neoui"
|
||||
PLUG_LIBS="$(pkgconf --libs x11 xft fontconfig freetype2 pango pangoxft alsa)"
|
||||
MEDIA_LIBS="$(pkgconf --libs libjpeg libpng)"
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -Wl,-soname,libneoui.so -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/neoui/neoui.cpp $PLUG_LIBS $MEDIA_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so
|
||||
cp -f /bananarchy/src/neoui/neoui.h /bananarchy/prebuilt/sxmo-x11/usr/include/neoui.h
|
||||
cp -f /bananarchy/src/neoui/neoui.h "$SYSROOT/usr/include/neoui.h"
|
||||
cp -f /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so "$SYSROOT/usr/lib/libneoui.so"
|
||||
NEOUI_LIBS="-L/bananarchy/prebuilt/sxmo-x11/usr/lib -lneoui"
|
||||
|
||||
echo "[7/7] Compiling DWM Plugins (linked against libneoui.so) and dwm-plugin runner..."
|
||||
mkdir -p /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/xdrawer/xdrawer.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/xdrawer/xdrawer.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/dialer_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/dialer_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/calllog_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/calllog_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/callscreen_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/callscreen_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/contacts_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/contacts_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/sms_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/sms_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/files_plugin.cpp $PLUG_LIBS $MEDIA_LIBS \
|
||||
/bananarchy/src/dwm-plugins/files_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/camera_plugin.cpp $PLUG_LIBS $MEDIA_LIBS -lpthread \
|
||||
/bananarchy/src/dwm-plugins/camera_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS -lpthread \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/themes_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/themes_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/modem_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/modem_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/networks_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/networks_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/ringtones_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/ringtones_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/wallpapers_plugin.cpp $PLUG_LIBS $MEDIA_LIBS \
|
||||
/bananarchy/src/dwm-plugins/wallpapers_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so
|
||||
|
||||
$CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \
|
||||
/bananarchy/src/dwm-plugins/music_plugin.cpp $PLUG_LIBS \
|
||||
/bananarchy/src/dwm-plugins/music_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \
|
||||
-o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so
|
||||
|
||||
$STRIP --strip-unneeded \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so \
|
||||
@@ -209,12 +221,16 @@ EOF
|
||||
ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xmusic
|
||||
ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xplayer
|
||||
|
||||
mkdir -p /bananarchy/overlay/rootfs/usr/bin /bananarchy/overlay/rootfs/usr/lib/dwm/plugins
|
||||
mkdir -p /bananarchy/overlay/rootfs/usr/bin /bananarchy/overlay/rootfs/usr/lib/dwm/plugins /bananarchy/overlay/rootfs/usr/include
|
||||
cp -a /bananarchy/prebuilt/sxmo-x11/usr/bin/. /bananarchy/overlay/rootfs/usr/bin/
|
||||
cp -f /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so /bananarchy/overlay/rootfs/usr/lib/libneoui.so
|
||||
cp -f /bananarchy/prebuilt/sxmo-x11/usr/include/neoui.h /bananarchy/overlay/rootfs/usr/include/neoui.h
|
||||
cp -a /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/. /bananarchy/overlay/rootfs/usr/lib/dwm/plugins/
|
||||
if [ -d /target-rootfs/usr/bin ]; then
|
||||
mkdir -p /target-rootfs/usr/lib/dwm/plugins
|
||||
mkdir -p /target-rootfs/usr/lib/dwm/plugins /target-rootfs/usr/include
|
||||
cp -a /bananarchy/prebuilt/sxmo-x11/usr/bin/. /target-rootfs/usr/bin/
|
||||
cp -f /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so /target-rootfs/usr/lib/libneoui.so
|
||||
cp -f /bananarchy/prebuilt/sxmo-x11/usr/include/neoui.h /target-rootfs/usr/include/neoui.h
|
||||
cp -a /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/. /target-rootfs/usr/lib/dwm/plugins/
|
||||
fi
|
||||
|
||||
@@ -222,6 +238,8 @@ EOF
|
||||
/bananarchy/prebuilt/sxmo-x11 \
|
||||
/bananarchy/overlay/rootfs/usr/bin \
|
||||
/bananarchy/overlay/rootfs/usr/lib \
|
||||
/bananarchy/overlay/rootfs/usr/include \
|
||||
/bananarchy/src/neoui \
|
||||
/bananarchy/src/sxmo-st \
|
||||
/bananarchy/src/sxmo-dmenu \
|
||||
/bananarchy/src/sxmo-dwm \
|
||||
@@ -231,5 +249,7 @@ EOF
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/bin/dmenu \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/bin/dwm \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/bin/dwm-plugin \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/include/neoui.h \
|
||||
/bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/*.so
|
||||
'
|
||||
@@ -75,52 +75,24 @@ int calllog_run_main(int argc, char** argv) {
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xcalllog", "XCallLog", "Call Log")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0x005577;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
StructureNotifyMask | VisibilityChangeMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xcalllog";
|
||||
char resClass[] = "XCallLog";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Call Log");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
|
||||
PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
nullptr, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -250,27 +222,11 @@ int calllog_run_main(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
constexpr int kHeaderH = 34;
|
||||
@@ -1136,16 +1092,6 @@ int calllog_run_main(int argc, char** argv) {
|
||||
}
|
||||
::unlink(getPluginFifoPath("calllog").c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -389,53 +389,25 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
saChld.sa_flags = SA_NOCLDSTOP;
|
||||
sigaction(SIGCHLD, &saChld, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xcallscreen", "XCallScreen", "Call Screen")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0x005577;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
StructureNotifyMask | VisibilityChangeMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xcallscreen";
|
||||
char resClass[] = "XCallScreen";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Call Screen");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
|
||||
PangoLayout* layoutNum = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
|
||||
PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutNum = neo.layoutNum;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -736,27 +708,11 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
constexpr int kHeaderH = 116;
|
||||
@@ -1819,17 +1775,6 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
::unlink(getPluginFifoPath("callscreen").c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(layoutNum);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,30 +116,31 @@ std::vector<PhotoEntry> listSavedPhotos() {
|
||||
void saveZoomedRgb24AsJpeg(const std::string& path,
|
||||
const uint8_t* src800x600,
|
||||
int zoomFactor) {
|
||||
if (zoomFactor <= 1) {
|
||||
saveRgb24AsJpeg(path, src800x600, kCamW, kCamH, 92);
|
||||
return;
|
||||
}
|
||||
// Rotate 90 degrees clockwise from raw 800x600 sensor into upright 600x800
|
||||
constexpr int kOutW = kCamH; // 600
|
||||
constexpr int kOutH = kCamW; // 800
|
||||
zoomFactor = std::clamp(zoomFactor, 1, 4);
|
||||
int cropW = kCamW / zoomFactor;
|
||||
int cropH = kCamH / zoomFactor;
|
||||
int startX = (kCamW - cropW) / 2;
|
||||
int startY = (kCamH - cropH) / 2;
|
||||
int cropRotW = kOutW / zoomFactor;
|
||||
int cropRotH = kOutH / zoomFactor;
|
||||
int startRotX = (kOutW - cropRotW) / 2;
|
||||
int startRotY = (kOutH - cropRotH) / 2;
|
||||
|
||||
std::vector<uint8_t> zoomed(kCamFrameBytes);
|
||||
for (int dy = 0; dy < kCamH; ++dy) {
|
||||
int sy = startY + (dy * cropH) / kCamH;
|
||||
const uint8_t* srow = src800x600 + static_cast<size_t>(sy) * kCamW * 3;
|
||||
uint8_t* drow = zoomed.data() + static_cast<size_t>(dy) * kCamW * 3;
|
||||
for (int dx = 0; dx < kCamW; ++dx) {
|
||||
int sx = startX + (dx * cropW) / kCamW;
|
||||
const uint8_t* px = srow + sx * 3;
|
||||
std::vector<uint8_t> rotated(kCamFrameBytes);
|
||||
for (int dy = 0; dy < kOutH; ++dy) {
|
||||
int rotY = std::clamp(startRotY + (dy * cropRotH) / kOutH, 0, kCamW - 1);
|
||||
int sx = rotY;
|
||||
uint8_t* drow = rotated.data() + static_cast<size_t>(dy) * kOutW * 3;
|
||||
for (int dx = 0; dx < kOutW; ++dx) {
|
||||
int rotX = std::clamp(startRotX + (dx * cropRotW) / kOutW, 0, kCamH - 1);
|
||||
int sy = (kCamH - 1) - rotX;
|
||||
const uint8_t* px =
|
||||
src800x600 + (static_cast<size_t>(sy) * kCamW + sx) * 3;
|
||||
drow[dx * 3 + 0] = px[0];
|
||||
drow[dx * 3 + 1] = px[1];
|
||||
drow[dx * 3 + 2] = px[2];
|
||||
}
|
||||
}
|
||||
saveRgb24AsJpeg(path, zoomed.data(), kCamW, kCamH, 92);
|
||||
saveRgb24AsJpeg(path, rotated.data(), kOutW, kOutH, 92);
|
||||
}
|
||||
|
||||
int runCameraApp(int argc, char** argv) {
|
||||
@@ -184,8 +185,8 @@ int runCameraApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xcamera", "XCamera", "Camera")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
if (vfPipe[0] >= 0) ::close(vfPipe[0]);
|
||||
if (vfPipe[1] >= 0) ::close(vfPipe[1]);
|
||||
@@ -193,40 +194,13 @@ int runCameraApp(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xcamera";
|
||||
char resClass[] = "XCamera";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Camera");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
@@ -487,47 +461,13 @@ int runCameraApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, centerLabel.c_str(),
|
||||
static_cast<int>(centerLabel.size()));
|
||||
int cw = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
|
||||
centerLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, rightLabel.c_str(),
|
||||
static_cast<int>(rightLabel.size()));
|
||||
int rw = 0, rhh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawUI = [&]() {
|
||||
|
||||
@@ -96,53 +96,24 @@ int runContactsApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xcontacts", "XContacts", "Contacts")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0x005577;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xcontacts";
|
||||
char resClass[] = "XContacts";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Contacts");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
|
||||
PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
nullptr, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -243,27 +214,11 @@ int runContactsApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
constexpr int kHeaderH = 38;
|
||||
@@ -276,25 +231,7 @@ int runContactsApp(int argc, char** argv) {
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel,
|
||||
XftColor* centerCol = nullptr) {
|
||||
int sbY = kWinHeight - kSoftbarH;
|
||||
XSetForeground(dpy, gc, theme.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, kSoftbarH);
|
||||
XSetForeground(dpy, gc, theme.spec.border);
|
||||
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, 1);
|
||||
|
||||
if (!leftLabel.empty()) {
|
||||
drawPango(layoutMain, &colLight, 6, sbY + 1, kSoftbarH - 1, leftLabel);
|
||||
}
|
||||
if (!centerLabel.empty()) {
|
||||
int cw = pangoWidth(layoutMain, centerLabel);
|
||||
drawPango(layoutMain, centerCol ? centerCol : &colGreen,
|
||||
(kWinWidth - cw) / 2, sbY + 1, kSoftbarH - 1, centerLabel);
|
||||
}
|
||||
if (!rightLabel.empty()) {
|
||||
int rw = pangoWidth(layoutMain, rightLabel);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, sbY + 1,
|
||||
kSoftbarH - 1, rightLabel);
|
||||
}
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, centerCol, kSoftbarH);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -1794,16 +1731,6 @@ int runContactsApp(int argc, char** argv) {
|
||||
}
|
||||
::unlink(getPluginFifoPath("contacts").c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,53 +66,26 @@ int dialer_run_main(int argc, char** argv) {
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xdialer", "XDialer", "Dialer")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0x005577;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
StructureNotifyMask | VisibilityChangeMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xdialer";
|
||||
char resClass[] = "XDialer";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Dialer");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
|
||||
PangoLayout* layoutNum = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
|
||||
PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
XftDraw* xftDraw = neo.xftDraw;
|
||||
PangoLayout* layoutNum = neo.layoutNum;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -206,27 +179,11 @@ int dialer_run_main(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
constexpr int kHeaderH = 56;
|
||||
@@ -989,17 +946,6 @@ int dialer_run_main(int argc, char** argv) {
|
||||
}
|
||||
::unlink(getPluginFifoPath("dialer").c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(layoutNum);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -320,47 +320,20 @@ int runFilesApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xfiles", "XFiles", "Files")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xfiles";
|
||||
char resClass[] = "XFiles";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Files");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
@@ -899,47 +872,13 @@ int runFilesApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, centerLabel.c_str(),
|
||||
static_cast<int>(centerLabel.size()));
|
||||
int cw = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
|
||||
centerLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, rightLabel.c_str(),
|
||||
static_cast<int>(rightLabel.size()));
|
||||
int rw = 0, rhh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawUI = [&]() {
|
||||
|
||||
@@ -1,341 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// Thin compatibility header forwarding to NeoUI (src/neoui/neoui.h)
|
||||
|
||||
#ifndef DWM_PLUGINS_MEDIA_UTILS_H
|
||||
#define DWM_PLUGINS_MEDIA_UTILS_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <csetjmp>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <jpeglib.h>
|
||||
#include <png.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace bananarchy {
|
||||
|
||||
struct JpegErrMgr {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmpBuf;
|
||||
};
|
||||
|
||||
inline void jpegErrorExit(j_common_ptr cinfo) {
|
||||
JpegErrMgr* myerr = reinterpret_cast<JpegErrMgr*>(cinfo->err);
|
||||
longjmp(myerr->setjmpBuf, 1);
|
||||
}
|
||||
|
||||
inline bool saveRgb24AsJpeg(const std::string& path,
|
||||
const uint8_t* rgb,
|
||||
int width,
|
||||
int height,
|
||||
int quality = 92) {
|
||||
if (!rgb || width <= 0 || height <= 0) {
|
||||
return false;
|
||||
}
|
||||
FILE* fp = std::fopen(path.c_str(), "wb");
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct jpeg_compress_struct cinfo {};
|
||||
JpegErrMgr jerr {};
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = jpegErrorExit;
|
||||
if (setjmp(jerr.setjmpBuf)) {
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
std::fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
jpeg_stdio_dest(&cinfo, fp);
|
||||
cinfo.image_width = static_cast<JDIMENSION>(width);
|
||||
cinfo.image_height = static_cast<JDIMENSION>(height);
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
int rowStride = width * 3;
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
JSAMPROW rowPtr =
|
||||
const_cast<JSAMPROW>(rgb + cinfo.next_scanline * rowStride);
|
||||
jpeg_write_scanlines(&cinfo, &rowPtr, 1);
|
||||
}
|
||||
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
std::fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool loadJpegRgb24(const std::string& path,
|
||||
std::vector<uint8_t>* outRgb,
|
||||
int* outW,
|
||||
int* outH) {
|
||||
FILE* fp = std::fopen(path.c_str(), "rb");
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct jpeg_decompress_struct cinfo {};
|
||||
JpegErrMgr jerr {};
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = jpegErrorExit;
|
||||
if (setjmp(jerr.setjmpBuf)) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
std::fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, fp);
|
||||
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
std::fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use libjpeg fast DCT downscaling for large images so decoding is instant
|
||||
if (cinfo.image_width > 960 || cinfo.image_height > 960) {
|
||||
cinfo.scale_num = 1;
|
||||
cinfo.scale_denom = 2;
|
||||
}
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
int w = static_cast<int>(cinfo.output_width);
|
||||
int h = static_cast<int>(cinfo.output_height);
|
||||
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
std::fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
outRgb->resize(static_cast<size_t>(w) * h * 3);
|
||||
int rowStride = w * 3;
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
JSAMPROW rowPtr = outRgb->data() + cinfo.output_scanline * rowStride;
|
||||
jpeg_read_scanlines(&cinfo, &rowPtr, 1);
|
||||
}
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
std::fclose(fp);
|
||||
*outW = w;
|
||||
*outH = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool loadPngRgb24(const std::string& path,
|
||||
std::vector<uint8_t>* outRgb,
|
||||
int* outW,
|
||||
int* outH) {
|
||||
png_image image {};
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
if (!png_image_begin_read_from_file(&image, path.c_str())) {
|
||||
return false;
|
||||
}
|
||||
image.format = PNG_FORMAT_RGB;
|
||||
int w = static_cast<int>(image.width);
|
||||
int h = static_cast<int>(image.height);
|
||||
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
|
||||
png_image_free(&image);
|
||||
return false;
|
||||
}
|
||||
outRgb->resize(PNG_IMAGE_SIZE(image));
|
||||
if (!png_image_finish_read(&image, nullptr, outRgb->data(), 0, nullptr)) {
|
||||
png_image_free(&image);
|
||||
return false;
|
||||
}
|
||||
png_image_free(&image);
|
||||
*outW = w;
|
||||
*outH = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool loadFfmpegImageRgb24(const std::string& path,
|
||||
std::vector<uint8_t>* outRgb,
|
||||
int* outW,
|
||||
int* outH) {
|
||||
int pipefd[2];
|
||||
if (::pipe(pipefd) != 0) {
|
||||
return false;
|
||||
}
|
||||
pid_t pid = ::fork();
|
||||
if (pid < 0) {
|
||||
::close(pipefd[0]);
|
||||
::close(pipefd[1]);
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
::close(pipefd[0]);
|
||||
::dup2(pipefd[1], STDOUT_FILENO);
|
||||
if (pipefd[1] != STDOUT_FILENO) ::close(pipefd[1]);
|
||||
int devnull = ::open("/dev/null", O_RDWR);
|
||||
if (devnull >= 0) {
|
||||
::dup2(devnull, STDIN_FILENO);
|
||||
::dup2(devnull, STDERR_FILENO);
|
||||
if (devnull > 2) ::close(devnull);
|
||||
}
|
||||
::execlp("ffmpeg", "ffmpeg", "-v", "error", "-i", path.c_str(),
|
||||
"-frames:v", "1", "-f", "image2pipe", "-vcodec", "png", "-",
|
||||
static_cast<char*>(nullptr));
|
||||
::_exit(127);
|
||||
}
|
||||
::close(pipefd[1]);
|
||||
std::vector<uint8_t> pngBuf;
|
||||
uint8_t chunk[4096];
|
||||
ssize_t n = 0;
|
||||
while ((n = ::read(pipefd[0], chunk, sizeof(chunk))) > 0) {
|
||||
if (pngBuf.size() + static_cast<size_t>(n) > 16 * 1024 * 1024) break;
|
||||
pngBuf.insert(pngBuf.end(), chunk, chunk + n);
|
||||
}
|
||||
::close(pipefd[0]);
|
||||
int status = 0;
|
||||
::waitpid(pid, &status, 0);
|
||||
if (pngBuf.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
png_image image {};
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
if (!png_image_begin_read_from_memory(&image, pngBuf.data(), pngBuf.size())) {
|
||||
return false;
|
||||
}
|
||||
image.format = PNG_FORMAT_RGB;
|
||||
int w = static_cast<int>(image.width);
|
||||
int h = static_cast<int>(image.height);
|
||||
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
|
||||
png_image_free(&image);
|
||||
return false;
|
||||
}
|
||||
outRgb->resize(PNG_IMAGE_SIZE(image));
|
||||
if (!png_image_finish_read(&image, nullptr, outRgb->data(), 0, nullptr)) {
|
||||
png_image_free(&image);
|
||||
return false;
|
||||
}
|
||||
png_image_free(&image);
|
||||
*outW = w;
|
||||
*outH = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool loadImageRgb24(const std::string& path,
|
||||
std::vector<uint8_t>* outRgb,
|
||||
int* outW,
|
||||
int* outH) {
|
||||
std::string low = path;
|
||||
for (char& c : low) {
|
||||
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
}
|
||||
if (low.size() >= 4 && low.substr(low.size() - 4) == ".png") {
|
||||
if (loadPngRgb24(path, outRgb, outW, outH)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (loadJpegRgb24(path, outRgb, outW, outH)) {
|
||||
return true;
|
||||
}
|
||||
if (loadPngRgb24(path, outRgb, outW, outH)) {
|
||||
return true;
|
||||
}
|
||||
if (loadFfmpegImageRgb24(path, outRgb, outW, outH)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb,
|
||||
int srcW,
|
||||
int srcH,
|
||||
uint32_t* dstBgrx,
|
||||
int canvasW,
|
||||
int canvasH,
|
||||
uint32_t bgPixel = 0x111111) {
|
||||
for (int i = 0; i < canvasW * canvasH; ++i) {
|
||||
dstBgrx[i] = bgPixel;
|
||||
}
|
||||
if (!srcRgb || srcW <= 0 || srcH <= 0 || canvasW <= 0 || canvasH <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int drawW = canvasW;
|
||||
int drawH = (srcH * canvasW) / srcW;
|
||||
if (drawH > canvasH) {
|
||||
drawH = canvasH;
|
||||
drawW = (srcW * canvasH) / srcH;
|
||||
}
|
||||
drawW = std::max(1, drawW);
|
||||
drawH = std::max(1, drawH);
|
||||
|
||||
int offX = (canvasW - drawW) / 2;
|
||||
int offY = (canvasH - drawH) / 2;
|
||||
|
||||
for (int dy = 0; dy < drawH; ++dy) {
|
||||
int sy = std::min(srcH - 1, (dy * srcH) / drawH);
|
||||
const uint8_t* srow = srcRgb + static_cast<size_t>(sy) * srcW * 3;
|
||||
uint32_t* drow = dstBgrx + static_cast<size_t>(offY + dy) * canvasW + offX;
|
||||
for (int dx = 0; dx < drawW; ++dx) {
|
||||
int sx = std::min(srcW - 1, (dx * srcW) / drawW);
|
||||
const uint8_t* px = srow + sx * 3;
|
||||
drow[dx] = (static_cast<uint32_t>(px[0]) << 16) |
|
||||
(static_cast<uint32_t>(px[1]) << 8) |
|
||||
static_cast<uint32_t>(px[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
|
||||
uint32_t* dstBgrx,
|
||||
int zoomFactor = 1) {
|
||||
if (!srcRgb || !dstBgrx) {
|
||||
return;
|
||||
}
|
||||
zoomFactor = std::clamp(zoomFactor, 1, 4);
|
||||
int cropW = 800 / zoomFactor;
|
||||
int cropH = 600 / zoomFactor;
|
||||
int startX = (800 - cropW) / 2;
|
||||
int startY = (600 - cropH) / 2;
|
||||
|
||||
for (int dy = 0; dy < 180; ++dy) {
|
||||
int sy = startY + (dy * cropH) / 180;
|
||||
const uint8_t* srow = srcRgb + static_cast<size_t>(sy) * 800 * 3;
|
||||
uint32_t* drow = dstBgrx + static_cast<size_t>(dy) * 240;
|
||||
for (int dx = 0; dx < 240; ++dx) {
|
||||
int sx = startX + (dx * cropW) / 240;
|
||||
const uint8_t* px = srow + sx * 3;
|
||||
drow[dx] = (static_cast<uint32_t>(px[0]) << 16) |
|
||||
(static_cast<uint32_t>(px[1]) << 8) |
|
||||
static_cast<uint32_t>(px[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string formatFileSize(off_t bytes) {
|
||||
char buf[32];
|
||||
if (bytes >= 1024LL * 1024LL * 1024LL) {
|
||||
std::snprintf(buf, sizeof(buf), "%.1fG",
|
||||
static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0));
|
||||
} else if (bytes >= 1024LL * 1024LL) {
|
||||
std::snprintf(buf, sizeof(buf), "%.1fM",
|
||||
static_cast<double>(bytes) / (1024.0 * 1024.0));
|
||||
} else if (bytes >= 1024LL) {
|
||||
std::snprintf(buf, sizeof(buf), "%.1fK",
|
||||
static_cast<double>(bytes) / 1024.0);
|
||||
} else {
|
||||
std::snprintf(buf, sizeof(buf), "%lldB", static_cast<long long>(bytes));
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
} // namespace bananarchy
|
||||
#include "../neoui/neoui.h"
|
||||
|
||||
#endif // DWM_PLUGINS_MEDIA_UTILS_H
|
||||
@@ -503,48 +503,19 @@ int runModemApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xmodem", "XModem", "Modem & SIM")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xmodem";
|
||||
char resClass[] = "XModem";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Modem & SIM");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
XftDraw* xftDraw = neo.xftDraw;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
@@ -693,44 +664,17 @@ int runModemApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) -> int {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoTextWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
return tw;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
int cw = pangoTextWidth(layoutMain, centerLabel);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26, centerLabel);
|
||||
int rw = pangoTextWidth(layoutMain, rightLabel);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawSignalBars = [&](int x, int y, int pct) {
|
||||
|
||||
@@ -321,51 +321,21 @@ int runMusicApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xmusic", "XMusic", "Music",
|
||||
kWinX, kWinY, kWinWidth, kWinHeight)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xmusic";
|
||||
char resClass[] = "XMusic";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Music");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = neo.layoutMain;
|
||||
auto& layoutSmall = neo.layoutSmall;
|
||||
auto& layoutIcon = neo.layoutIcon;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
@@ -884,35 +854,13 @@ int runMusicApp(int argc, char** argv) {
|
||||
int h, const std::string& text, int maxW = -1,
|
||||
int align = 0) {
|
||||
if (text.empty()) return;
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int tx = x;
|
||||
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
|
||||
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
|
||||
int ty = y + (h - th) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW, align);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& midLabel,
|
||||
const std::string& rightLabel) {
|
||||
int barY = kWinHeight - 24;
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
|
||||
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
|
||||
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
|
||||
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -1568,11 +1516,6 @@ int runMusicApp(int argc, char** argv) {
|
||||
stopMpvDaemon();
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
if (xftDraw) XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -374,51 +374,21 @@ int runNetworksApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xnetworks", "XNetworks", "Networks & Bluetooth",
|
||||
kWinX, kWinY, kWinWidth, kWinHeight)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xnetworks";
|
||||
char resClass[] = "XNetworks";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Networks & Bluetooth");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = neo.layoutMain;
|
||||
auto& layoutSmall = neo.layoutSmall;
|
||||
auto& layoutIcon = neo.layoutIcon;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
@@ -587,44 +557,17 @@ int runNetworksApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) -> int {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoTextWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
return tw;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
int cw = pangoTextWidth(layoutMain, centerLabel);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26, centerLabel);
|
||||
int rw = pangoTextWidth(layoutMain, rightLabel);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -1524,11 +1467,6 @@ int runNetworksApp(int argc, char** argv) {
|
||||
hideWindow();
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreePixmap(dpy, pix);
|
||||
XFreeGC(dpy, gc);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2726,107 +2726,6 @@ inline constexpr const char* kMultiTapPunct1 =
|
||||
inline constexpr const char* kMultiTapStar =
|
||||
"*#+-=_/\\|~`@$%^&()[]{}<>'\".,!?:;";
|
||||
|
||||
inline std::string formatMultiTapBar(const std::string& prefix,
|
||||
const char* table, int activeIdx,
|
||||
bool makeUpper,
|
||||
int maxItems = 7,
|
||||
size_t maxChars = 21) {
|
||||
if (!table || !table[0]) return "";
|
||||
int total = static_cast<int>(std::strlen(table));
|
||||
if (total <= 0) return "";
|
||||
activeIdx = std::clamp(activeIdx, 0, total - 1);
|
||||
|
||||
std::vector<std::string> labels;
|
||||
labels.reserve(total);
|
||||
for (int i = 0; i < total; ++i) {
|
||||
char c = table[i];
|
||||
if (c == ' ') {
|
||||
labels.push_back("SPC");
|
||||
} else if (c == '\n') {
|
||||
labels.push_back("NL");
|
||||
} else if (c == '\t') {
|
||||
labels.push_back("TAB");
|
||||
} else {
|
||||
if (makeUpper && std::isalpha(static_cast<unsigned char>(c))) {
|
||||
c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
}
|
||||
labels.push_back(std::string(1, c));
|
||||
}
|
||||
}
|
||||
|
||||
int halfWin = std::max(1, maxItems / 2);
|
||||
int start = std::max(0, activeIdx - halfWin);
|
||||
int end = start;
|
||||
size_t width = 0;
|
||||
int count = 0;
|
||||
|
||||
while (start <= activeIdx) {
|
||||
width = 0;
|
||||
count = 0;
|
||||
end = start;
|
||||
while (end < total && count < maxItems) {
|
||||
size_t iw = labels[end].size() + 2;
|
||||
if (count > 0 && width + iw > maxChars) break;
|
||||
width += iw;
|
||||
++end;
|
||||
++count;
|
||||
}
|
||||
if (activeIdx < end) break;
|
||||
++start;
|
||||
}
|
||||
|
||||
while (start > 0 && count < maxItems) {
|
||||
size_t iw = labels[start - 1].size() + 2;
|
||||
if (width + iw > maxChars) break;
|
||||
--start;
|
||||
width += iw;
|
||||
++count;
|
||||
}
|
||||
|
||||
std::string out = prefix;
|
||||
out += (start > 0) ? "<" : " ";
|
||||
for (int i = start; i < end; ++i) {
|
||||
if (i == activeIdx) {
|
||||
out += "[" + labels[i] + "]";
|
||||
} else {
|
||||
out += " " + labels[i] + " ";
|
||||
}
|
||||
}
|
||||
if (end < total) {
|
||||
out += ">";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::string tailFitPangoText(PangoLayout* layout,
|
||||
const std::string& text,
|
||||
int maxWidthPx) {
|
||||
if (!layout || text.empty() || maxWidthPx <= 0) return text;
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
int w = 0, h = 0;
|
||||
pango_layout_get_pixel_size(layout, &w, &h);
|
||||
if (w <= maxWidthPx) return text;
|
||||
|
||||
size_t pos = 0;
|
||||
while (pos < text.size()) {
|
||||
pos++;
|
||||
while (pos < text.size() &&
|
||||
(static_cast<unsigned char>(text[pos]) & 0xC0) == 0x80) {
|
||||
pos++;
|
||||
}
|
||||
std::string candidate = ".." + text.substr(pos);
|
||||
pango_layout_set_text(layout, candidate.c_str(),
|
||||
static_cast<int>(candidate.size()));
|
||||
pango_layout_get_pixel_size(layout, &w, &h);
|
||||
if (w <= maxWidthPx) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace bananarchy
|
||||
|
||||
#endif // DWM_PLUGINS_PHONE_DATA_H
|
||||
@@ -247,11 +247,6 @@ void saveRingSettings(const RingSettings& s) {
|
||||
runAsyncCmd("sxmo_hook_statusbar.sh audio >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
std::string formatFileSize(off_t bytes) {
|
||||
if (bytes < 1024) return std::to_string(bytes) + " B";
|
||||
return std::to_string((bytes + 512) / 1024) + " KB";
|
||||
}
|
||||
|
||||
int runRingtonesApp(int argc, char** argv) {
|
||||
gRunning = 1;
|
||||
std::setlocale(LC_ALL, "");
|
||||
@@ -283,50 +278,20 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xringtones", "XRingtones", "Ringtones",
|
||||
kWinX, kWinY, kWinWidth, kWinHeight)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xringtones";
|
||||
char resClass[] = "XRingtones";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Ringtones");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = neo.layoutMain;
|
||||
auto& layoutSmall = neo.layoutSmall;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
@@ -448,35 +413,13 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
int h, const std::string& text, int maxW = -1,
|
||||
int align = 0) {
|
||||
if (text.empty()) return;
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int tx = x;
|
||||
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
|
||||
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
|
||||
int ty = y + (h - th) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW, align);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& midLabel,
|
||||
const std::string& rightLabel) {
|
||||
int barY = kWinHeight - 24;
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
|
||||
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
|
||||
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
|
||||
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -913,11 +856,6 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
hideWindow();
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
if (xftDraw) XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,8 +118,8 @@ int runSmsApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xsms", "XSms", "Messages")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
if (notifyPipe[0] >= 0) ::close(notifyPipe[0]);
|
||||
if (notifyPipe[1] >= 0) ::close(notifyPipe[1]);
|
||||
@@ -127,40 +127,12 @@ int runSmsApp(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xsms";
|
||||
char resClass[] = "XSms";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Messages");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
XftDraw* xftDraw = neo.xftDraw;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
@@ -464,47 +436,13 @@ int runSmsApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, centerLabel.c_str(),
|
||||
static_cast<int>(centerLabel.size()));
|
||||
int cw = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
|
||||
centerLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, rightLabel.c_str(),
|
||||
static_cast<int>(rightLabel.size()));
|
||||
int rw = 0, rhh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawUI = [&]() {
|
||||
|
||||
+4
-631
@@ -1,636 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// Thin compatibility header forwarding to NeoUI (src/neoui/neoui.h)
|
||||
|
||||
#ifndef DWM_PLUGINS_THEME_H
|
||||
#define DWM_PLUGINS_THEME_H
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace bananarchy {
|
||||
|
||||
inline std::string themeTrim(const std::string& s) {
|
||||
size_t b = 0;
|
||||
while (b < s.size() && std::isspace(static_cast<unsigned char>(s[b]))) {
|
||||
++b;
|
||||
}
|
||||
size_t e = s.size();
|
||||
while (e > b && std::isspace(static_cast<unsigned char>(s[e - 1]))) {
|
||||
--e;
|
||||
}
|
||||
if (e >= b + 2 &&
|
||||
((s[b] == '"' && s[e - 1] == '"') || (s[b] == '\'' && s[e - 1] == '\''))) {
|
||||
return s.substr(b + 1, e - b - 2);
|
||||
}
|
||||
return s.substr(b, e - b);
|
||||
}
|
||||
|
||||
inline int themeHexNibble(char c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
|
||||
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline bool parseHexRgb(const std::string& raw, uint32_t* outRgb) {
|
||||
std::string s = themeTrim(raw);
|
||||
if (s.rfind("0x", 0) == 0 || s.rfind("0X", 0) == 0) {
|
||||
s = "#" + s.substr(2);
|
||||
}
|
||||
if (s.size() == 7 && s[0] == '#') {
|
||||
uint32_t v = 0;
|
||||
for (int i = 1; i < 7; ++i) {
|
||||
int n = themeHexNibble(s[i]);
|
||||
if (n < 0) return false;
|
||||
v = (v << 4) | static_cast<uint32_t>(n);
|
||||
}
|
||||
*outRgb = v;
|
||||
return true;
|
||||
}
|
||||
if (s.size() == 4 && s[0] == '#') {
|
||||
int r = themeHexNibble(s[1]);
|
||||
int g = themeHexNibble(s[2]);
|
||||
int b = themeHexNibble(s[3]);
|
||||
if (r < 0 || g < 0 || b < 0) return false;
|
||||
*outRgb = static_cast<uint32_t>(((r * 17) << 16) | ((g * 17) << 8) | (b * 17));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::string formatHexRgb(uint32_t rgb) {
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof(buf), "#%06x", static_cast<unsigned int>(rgb & 0xffffffu));
|
||||
return buf;
|
||||
}
|
||||
|
||||
inline uint32_t adjustRgb(uint32_t rgb, int delta) {
|
||||
int r = std::clamp(static_cast<int>((rgb >> 16) & 0xff) + delta, 0, 255);
|
||||
int g = std::clamp(static_cast<int>((rgb >> 8) & 0xff) + delta, 0, 255);
|
||||
int b = std::clamp(static_cast<int>(rgb & 0xff) + delta, 0, 255);
|
||||
return static_cast<uint32_t>((r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
inline uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct) {
|
||||
int w2 = std::clamp(weight2Pct, 0, 100);
|
||||
int w1 = 100 - w2;
|
||||
int r = (((c1 >> 16) & 0xff) * w1 + ((c2 >> 16) & 0xff) * w2) / 100;
|
||||
int g = (((c1 >> 8) & 0xff) * w1 + ((c2 >> 8) & 0xff) * w2) / 100;
|
||||
int b = ((c1 & 0xff) * w1 + (c2 & 0xff) * w2) / 100;
|
||||
return static_cast<uint32_t>((std::clamp(r, 0, 255) << 16) |
|
||||
(std::clamp(g, 0, 255) << 8) |
|
||||
std::clamp(b, 0, 255));
|
||||
}
|
||||
|
||||
inline std::string getHomeDirPath() {
|
||||
const char* h = std::getenv("HOME");
|
||||
return (h && h[0]) ? h : "/home/user";
|
||||
}
|
||||
|
||||
inline std::string getXresourcesPath() {
|
||||
return getHomeDirPath() + "/.Xresources";
|
||||
}
|
||||
|
||||
inline std::string getThemesDirPath() {
|
||||
return getHomeDirPath() + "/.xthemes";
|
||||
}
|
||||
|
||||
struct ThemeSpec {
|
||||
std::string name = "Default";
|
||||
std::string fontFace = "Fira Code";
|
||||
std::string iconFontFace = "DejaVuSansM Nerd Font";
|
||||
int baseFontSize = 15;
|
||||
|
||||
// Core colors (24-bit RGB)
|
||||
uint32_t bgMain = 0x222222;
|
||||
uint32_t bgBar = 0x222222;
|
||||
uint32_t bgHeader = 0x1c1c1c;
|
||||
uint32_t bgFooter = 0x181818;
|
||||
uint32_t bgOverlay = 0x161616;
|
||||
uint32_t bgAltEven = 0x282828;
|
||||
uint32_t bgAltOdd = 0x2e2e2e;
|
||||
uint32_t bgInput = 0x1a1a1a;
|
||||
uint32_t bgInputFocus = 0x1b3b4b;
|
||||
uint32_t bgButton = 0x2a2a2a;
|
||||
uint32_t bgSearch = 0x383838;
|
||||
uint32_t bgBubbleIn = 0x262d32;
|
||||
uint32_t bgBubbleOut = 0x1f2d38;
|
||||
uint32_t bgToast = 0x102535;
|
||||
|
||||
uint32_t fgMain = 0xdddddd;
|
||||
uint32_t fgBright = 0xffffff;
|
||||
uint32_t fgMuted = 0x999999;
|
||||
|
||||
uint32_t selBg = 0x005577;
|
||||
uint32_t selFg = 0xffffff;
|
||||
uint32_t accent = 0xf4d03f;
|
||||
uint32_t accentAlt = 0x0088bb;
|
||||
uint32_t highlight = 0xffc978;
|
||||
uint32_t border = 0x444444;
|
||||
uint32_t divider = 0x666666;
|
||||
|
||||
uint32_t success = 0x2ecc71;
|
||||
uint32_t info = 0x5dade2;
|
||||
uint32_t warning = 0xe67e22;
|
||||
uint32_t danger = 0xe74c3c;
|
||||
uint32_t dangerBg = 0x922b21;
|
||||
|
||||
int sizeSmall() const {
|
||||
return std::max(8, static_cast<int>(std::lround(baseFontSize * 12.0 / 15.0)));
|
||||
}
|
||||
int sizeMain() const {
|
||||
return std::clamp(baseFontSize, 10, 24);
|
||||
}
|
||||
int sizeIcon() const {
|
||||
return std::max(10, static_cast<int>(std::lround(baseFontSize * 16.0 / 15.0)));
|
||||
}
|
||||
int sizeLarge() const {
|
||||
return std::max(11, static_cast<int>(std::lround(baseFontSize * 18.0 / 15.0)));
|
||||
}
|
||||
|
||||
std::string pangoMainFontStr() const {
|
||||
return fontFace + ", " + iconFontFace + " " + std::to_string(sizeMain()) + "px";
|
||||
}
|
||||
std::string pangoSmallFontStr() const {
|
||||
return fontFace + ", " + iconFontFace + " " + std::to_string(sizeSmall()) + "px";
|
||||
}
|
||||
std::string pangoIconFontStr() const {
|
||||
return iconFontFace + ", " + fontFace + " " + std::to_string(sizeIcon()) + "px";
|
||||
}
|
||||
std::string pangoLargeBoldFontStr() const {
|
||||
return fontFace + ", " + iconFontFace + " Bold " + std::to_string(sizeLarge()) + "px";
|
||||
}
|
||||
std::string xftFontStr(int pxSize) const {
|
||||
return fontFace + ":pixelsize=" + std::to_string(pxSize) +
|
||||
":style=Regular:antialias=true:autohint=true";
|
||||
}
|
||||
std::string xftIconFontStr(int pxSize) const {
|
||||
return iconFontFace + ":pixelsize=" + std::to_string(pxSize) +
|
||||
":style=Regular:antialias=true:autohint=true";
|
||||
}
|
||||
|
||||
void recomputeDerivedFromCore() {
|
||||
int luma = (((bgMain >> 16) & 0xff) * 299 +
|
||||
((bgMain >> 8) & 0xff) * 587 +
|
||||
(bgMain & 0xff) * 114) / 1000;
|
||||
int dir = (luma > 140) ? -1 : 1;
|
||||
|
||||
bgBar = bgMain;
|
||||
bgHeader = adjustRgb(bgMain, -dir * 6);
|
||||
bgFooter = adjustRgb(bgMain, -dir * 10);
|
||||
bgOverlay = adjustRgb(bgMain, -dir * 12);
|
||||
bgAltEven = adjustRgb(bgMain, dir * 6);
|
||||
bgAltOdd = adjustRgb(bgMain, dir * 12);
|
||||
bgInput = adjustRgb(bgMain, -dir * 8);
|
||||
bgInputFocus = blendRgb(bgMain, selBg, 40);
|
||||
bgButton = adjustRgb(bgMain, dir * 8);
|
||||
bgSearch = adjustRgb(bgMain, dir * 22);
|
||||
bgBubbleIn = blendRgb(bgMain, success, 14);
|
||||
bgBubbleOut = blendRgb(bgMain, selBg, 26);
|
||||
bgToast = blendRgb(bgOverlay, selBg, 35);
|
||||
|
||||
int fgLuma = (((fgMain >> 16) & 0xff) * 299 +
|
||||
((fgMain >> 8) & 0xff) * 587 +
|
||||
(fgMain & 0xff) * 114) / 1000;
|
||||
fgBright = (fgLuma > 128) ? 0xffffff : 0x000000;
|
||||
fgMuted = blendRgb(fgMain, bgMain, 45);
|
||||
|
||||
accentAlt = adjustRgb(selBg, 48);
|
||||
highlight = blendRgb(accent, 0xffffff, 30);
|
||||
border = adjustRgb(bgMain, dir * 34);
|
||||
divider = adjustRgb(bgMain, dir * 68);
|
||||
}
|
||||
|
||||
void parseFromMap(const std::unordered_map<std::string, std::string>& kv) {
|
||||
auto getStr = [&](const char* k1, const char* k2 = nullptr,
|
||||
const char* k3 = nullptr) -> std::string {
|
||||
auto it = kv.find(k1);
|
||||
if (it != kv.end() && !it->second.empty()) return it->second;
|
||||
if (k2) {
|
||||
it = kv.find(k2);
|
||||
if (it != kv.end() && !it->second.empty()) return it->second;
|
||||
}
|
||||
if (k3) {
|
||||
it = kv.find(k3);
|
||||
if (it != kv.end() && !it->second.empty()) return it->second;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
std::string nm = getStr("theme.name", "*themeName");
|
||||
if (!nm.empty()) name = nm;
|
||||
|
||||
std::string ff = getStr("theme.fontFace", "*fontFace");
|
||||
if (!ff.empty()) {
|
||||
fontFace = ff;
|
||||
} else {
|
||||
std::string dwmFont = getStr("dwm.font");
|
||||
if (!dwmFont.empty()) {
|
||||
size_t comma = dwmFont.find(',');
|
||||
if (comma != std::string::npos) {
|
||||
fontFace = themeTrim(dwmFont.substr(0, comma));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string iff = getStr("theme.iconFontFace", "*iconFontFace");
|
||||
if (!iff.empty()) iconFontFace = iff;
|
||||
|
||||
std::string bfs = getStr("theme.baseFontSize", "*baseFontSize");
|
||||
if (!bfs.empty()) {
|
||||
int sz = std::atoi(bfs.c_str());
|
||||
if (sz >= 10 && sz <= 24) baseFontSize = sz;
|
||||
} else {
|
||||
std::string dwmFont = getStr("dwm.font");
|
||||
size_t pxPos = dwmFont.rfind("px");
|
||||
if (pxPos != std::string::npos && pxPos > 0) {
|
||||
size_t sp = pxPos;
|
||||
while (sp > 0 && std::isdigit(static_cast<unsigned char>(dwmFont[sp - 1]))) {
|
||||
--sp;
|
||||
}
|
||||
if (sp < pxPos) {
|
||||
int sz = std::atoi(dwmFont.substr(sp, pxPos - sp).c_str());
|
||||
if (sz >= 10 && sz <= 24) baseFontSize = sz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto getCol = [&](uint32_t* dst, const char* k1, const char* k2 = nullptr,
|
||||
const char* k3 = nullptr) -> bool {
|
||||
std::string s = getStr(k1, k2, k3);
|
||||
if (s.empty()) return false;
|
||||
uint32_t v = 0;
|
||||
if (parseHexRgb(s, &v)) {
|
||||
*dst = v;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
bool hasCoreBg = getCol(&bgMain, "theme.bgMain", "*background", "dmenu.background");
|
||||
bool hasCoreFg = getCol(&fgMain, "theme.fgMain", "*foreground", "dwm.normfgcolor");
|
||||
bool hasSelBg = getCol(&selBg, "theme.selBg", "dmenu.selbackground", "dwm.selbgcolor");
|
||||
bool hasSelFg = getCol(&selFg, "theme.selFg", "dmenu.selforeground", "dwm.selfgcolor");
|
||||
bool hasAccent = getCol(&accent, "theme.accent", "*accentColor", "st.cursorColor");
|
||||
(void)hasCoreBg;
|
||||
(void)hasCoreFg;
|
||||
(void)hasSelBg;
|
||||
(void)hasSelFg;
|
||||
(void)hasAccent;
|
||||
|
||||
// Derive defaults from core colors first, then override with any explicit tokens
|
||||
recomputeDerivedFromCore();
|
||||
|
||||
getCol(&bgBar, "theme.bgBar", "dwm.background", "dwm.normbgcolor");
|
||||
getCol(&bgHeader, "theme.bgHeader", "dmenu.background", "st.background");
|
||||
getCol(&bgFooter, "theme.bgFooter");
|
||||
getCol(&bgOverlay, "theme.bgOverlay");
|
||||
getCol(&bgAltEven, "theme.bgAltEven");
|
||||
getCol(&bgAltOdd, "theme.bgAltOdd");
|
||||
getCol(&bgInput, "theme.bgInput");
|
||||
getCol(&bgInputFocus, "theme.bgInputFocus");
|
||||
getCol(&bgButton, "theme.bgButton");
|
||||
getCol(&bgSearch, "theme.bgSearch", "dmenu.outbackground");
|
||||
getCol(&bgBubbleIn, "theme.bgBubbleIn");
|
||||
getCol(&bgBubbleOut, "theme.bgBubbleOut");
|
||||
getCol(&bgToast, "theme.bgToast");
|
||||
|
||||
getCol(&fgBright, "theme.fgBright", "dmenu.selforeground");
|
||||
getCol(&fgMuted, "theme.fgMuted");
|
||||
|
||||
getCol(&accentAlt, "theme.accentAlt");
|
||||
getCol(&highlight, "theme.highlight", "dmenu.highlight");
|
||||
getCol(&border, "theme.border", "dwm.border", "dwm.normbordercolor");
|
||||
getCol(÷r, "theme.divider");
|
||||
|
||||
getCol(&success, "theme.success");
|
||||
getCol(&info, "theme.info");
|
||||
getCol(&warning, "theme.warning");
|
||||
getCol(&danger, "theme.danger");
|
||||
getCol(&dangerBg, "theme.dangerBg");
|
||||
}
|
||||
|
||||
static void parseLinesIntoMap(const std::string& content,
|
||||
std::unordered_map<std::string, std::string>& kv) {
|
||||
std::istringstream ss(content);
|
||||
std::string line;
|
||||
while (std::getline(ss, line)) {
|
||||
std::string t = themeTrim(line);
|
||||
if (t.empty() || t[0] == '!' || t[0] == '#') continue;
|
||||
size_t colon = t.find(':');
|
||||
if (colon == std::string::npos) continue;
|
||||
std::string key = themeTrim(t.substr(0, colon));
|
||||
std::string val = themeTrim(t.substr(colon + 1));
|
||||
if (!key.empty() && !val.empty()) {
|
||||
kv[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool loadFromFile(const std::string& path) {
|
||||
std::ifstream in(path);
|
||||
if (!in.is_open()) return false;
|
||||
std::ostringstream ss;
|
||||
ss << in.rdbuf();
|
||||
std::unordered_map<std::string, std::string> kv;
|
||||
parseLinesIntoMap(ss.str(), kv);
|
||||
parseFromMap(kv);
|
||||
return true;
|
||||
}
|
||||
|
||||
void loadActive(Display* dpy, int screen) {
|
||||
std::unordered_map<std::string, std::string> kv;
|
||||
if (dpy) {
|
||||
Atom actualType = None;
|
||||
int actualFormat = 0;
|
||||
unsigned long nitems = 0, bytesAfter = 0;
|
||||
unsigned char* prop = nullptr;
|
||||
if (XGetWindowProperty(dpy, RootWindow(dpy, screen), XA_RESOURCE_MANAGER,
|
||||
0L, 65536L, False, XA_STRING, &actualType,
|
||||
&actualFormat, &nitems, &bytesAfter,
|
||||
&prop) == Success &&
|
||||
prop) {
|
||||
if (actualType == XA_STRING && actualFormat == 8 && nitems > 0) {
|
||||
std::string resStr(reinterpret_cast<char*>(prop), nitems);
|
||||
parseLinesIntoMap(resStr, kv);
|
||||
}
|
||||
XFree(prop);
|
||||
}
|
||||
}
|
||||
// Also read ~/.Xresources so direct file edits always take effect
|
||||
std::ifstream in(getXresourcesPath());
|
||||
if (in.is_open()) {
|
||||
std::ostringstream ss;
|
||||
ss << in.rdbuf();
|
||||
parseLinesIntoMap(ss.str(), kv);
|
||||
}
|
||||
if (!kv.empty()) {
|
||||
parseFromMap(kv);
|
||||
}
|
||||
}
|
||||
|
||||
std::string serializeXresources() const {
|
||||
std::ostringstream out;
|
||||
out << "! Space to setup configversion\n";
|
||||
out << "! configversion: 7bff124b2de16292fe6e7a7e5d3322ae\n";
|
||||
out << "! Bananarchy Unified Theme: " << name << "\n\n";
|
||||
|
||||
out << "theme.name: " << name << "\n";
|
||||
out << "theme.fontFace: " << fontFace << "\n";
|
||||
out << "theme.iconFontFace: " << iconFontFace << "\n";
|
||||
out << "theme.baseFontSize: " << sizeMain() << "\n\n";
|
||||
|
||||
out << "theme.bgMain: " << formatHexRgb(bgMain) << "\n";
|
||||
out << "theme.bgBar: " << formatHexRgb(bgBar) << "\n";
|
||||
out << "theme.bgHeader: " << formatHexRgb(bgHeader) << "\n";
|
||||
out << "theme.bgFooter: " << formatHexRgb(bgFooter) << "\n";
|
||||
out << "theme.bgOverlay: " << formatHexRgb(bgOverlay) << "\n";
|
||||
out << "theme.bgAltEven: " << formatHexRgb(bgAltEven) << "\n";
|
||||
out << "theme.bgAltOdd: " << formatHexRgb(bgAltOdd) << "\n";
|
||||
out << "theme.bgInput: " << formatHexRgb(bgInput) << "\n";
|
||||
out << "theme.bgInputFocus: " << formatHexRgb(bgInputFocus) << "\n";
|
||||
out << "theme.bgButton: " << formatHexRgb(bgButton) << "\n";
|
||||
out << "theme.bgSearch: " << formatHexRgb(bgSearch) << "\n";
|
||||
out << "theme.bgBubbleIn: " << formatHexRgb(bgBubbleIn) << "\n";
|
||||
out << "theme.bgBubbleOut: " << formatHexRgb(bgBubbleOut) << "\n";
|
||||
out << "theme.bgToast: " << formatHexRgb(bgToast) << "\n\n";
|
||||
|
||||
out << "theme.fgMain: " << formatHexRgb(fgMain) << "\n";
|
||||
out << "theme.fgBright: " << formatHexRgb(fgBright) << "\n";
|
||||
out << "theme.fgMuted: " << formatHexRgb(fgMuted) << "\n\n";
|
||||
|
||||
out << "theme.selBg: " << formatHexRgb(selBg) << "\n";
|
||||
out << "theme.selFg: " << formatHexRgb(selFg) << "\n";
|
||||
out << "theme.accent: " << formatHexRgb(accent) << "\n";
|
||||
out << "theme.accentAlt: " << formatHexRgb(accentAlt) << "\n";
|
||||
out << "theme.highlight: " << formatHexRgb(highlight) << "\n";
|
||||
out << "theme.border: " << formatHexRgb(border) << "\n";
|
||||
out << "theme.divider: " << formatHexRgb(divider) << "\n\n";
|
||||
|
||||
out << "theme.success: " << formatHexRgb(success) << "\n";
|
||||
out << "theme.info: " << formatHexRgb(info) << "\n";
|
||||
out << "theme.warning: " << formatHexRgb(warning) << "\n";
|
||||
out << "theme.danger: " << formatHexRgb(danger) << "\n";
|
||||
out << "theme.dangerBg: " << formatHexRgb(dangerBg) << "\n\n";
|
||||
|
||||
out << "dmenu.font: " << xftFontStr(sizeLarge()) << "\n";
|
||||
out << "dmenu.background: " << formatHexRgb(bgHeader) << "\n";
|
||||
out << "dmenu.foreground: " << formatHexRgb(fgBright) << "\n";
|
||||
out << "dmenu.selbackground: " << formatHexRgb(selBg) << "\n";
|
||||
out << "dmenu.selforeground: " << formatHexRgb(selFg) << "\n";
|
||||
out << "dmenu.outbackground: " << formatHexRgb(bgSearch) << "\n";
|
||||
out << "dmenu.outforeground: " << formatHexRgb(fgBright) << "\n";
|
||||
out << "dmenu.highlight: " << formatHexRgb(highlight) << "\n\n";
|
||||
|
||||
out << "dwm.font: " << pangoMainFontStr() << "\n";
|
||||
out << "dwm.background: " << formatHexRgb(bgBar) << "\n";
|
||||
out << "dwm.foreground: " << formatHexRgb(fgMain) << "\n";
|
||||
out << "dwm.border: " << formatHexRgb(border) << "\n";
|
||||
out << "dwm.selbackground: " << formatHexRgb(selBg) << "\n";
|
||||
out << "dwm.selforeground: " << formatHexRgb(selFg) << "\n";
|
||||
out << "dwm.selborder: " << formatHexRgb(selBg) << "\n";
|
||||
out << "dwm.normbgcolor: " << formatHexRgb(bgBar) << "\n";
|
||||
out << "dwm.normbordercolor: " << formatHexRgb(border) << "\n";
|
||||
out << "dwm.normfgcolor: " << formatHexRgb(fgMain) << "\n";
|
||||
out << "dwm.selbgcolor: " << formatHexRgb(selBg) << "\n";
|
||||
out << "dwm.selbordercolor: " << formatHexRgb(selBg) << "\n";
|
||||
out << "dwm.selfgcolor: " << formatHexRgb(selFg) << "\n\n";
|
||||
|
||||
out << "st.font: " << xftFontStr(sizeLarge()) << "\n";
|
||||
out << "st.termname: xterm-256color\n";
|
||||
out << "st.background: " << formatHexRgb(bgHeader) << "\n";
|
||||
out << "st.foreground: " << formatHexRgb(fgMain) << "\n";
|
||||
out << "st.cursorColor: " << formatHexRgb(accent) << "\n\n";
|
||||
|
||||
out << "svkbd.font: " << fontFace << ":pixelsize=" << sizeSmall() << "\n";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
bool saveToFile(const std::string& path) const {
|
||||
std::ofstream out(path, std::ios::trunc);
|
||||
if (!out.is_open()) return false;
|
||||
out << serializeXresources();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0) {
|
||||
ThemeSpec spec;
|
||||
spec.loadActive(dpy, screen);
|
||||
return spec;
|
||||
}
|
||||
|
||||
struct PluginTheme {
|
||||
ThemeSpec spec;
|
||||
time_t lastXresMtime = -1;
|
||||
off_t lastXresSize = -1;
|
||||
bool colorsAllocated = false;
|
||||
|
||||
Display* dpy_ = nullptr;
|
||||
int screen_ = 0;
|
||||
Visual* visual_ = nullptr;
|
||||
Colormap cmap_ = 0;
|
||||
Window win_ = None;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
|
||||
XftColor colWhite{};
|
||||
XftColor colLight{};
|
||||
XftColor colMuted{};
|
||||
XftColor colYellow{};
|
||||
XftColor colGreen{};
|
||||
XftColor colBlue{};
|
||||
XftColor colOrange{};
|
||||
XftColor colRed{};
|
||||
|
||||
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
|
||||
XftColor* dst) {
|
||||
std::string hex = formatHexRgb(rgb);
|
||||
XftColorAllocName(dpy, visual, cmap, hex.c_str(), dst);
|
||||
}
|
||||
|
||||
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
Window win = None) {
|
||||
dpy_ = dpy;
|
||||
screen_ = screen;
|
||||
visual_ = visual;
|
||||
cmap_ = cmap;
|
||||
win_ = win;
|
||||
if (!pangoCtx && dpy) {
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
pangoCtx = pango_font_map_create_context(fontMap);
|
||||
layoutMain = pango_layout_new(pangoCtx);
|
||||
layoutSmall = pango_layout_new(pangoCtx);
|
||||
layoutIcon = pango_layout_new(pangoCtx);
|
||||
layoutNum = pango_layout_new(pangoCtx);
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
if (dpy_ && visual_) {
|
||||
load(dpy_, screen_, visual_, cmap_, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win_);
|
||||
}
|
||||
}
|
||||
|
||||
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr,
|
||||
PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr,
|
||||
PangoLayout* lNum = nullptr,
|
||||
Window win = None) {
|
||||
dpy_ = dpy;
|
||||
screen_ = screen;
|
||||
visual_ = visual;
|
||||
cmap_ = cmap;
|
||||
if (win != None) win_ = win;
|
||||
if (lMain) layoutMain = lMain;
|
||||
if (lSmall) layoutSmall = lSmall;
|
||||
if (lIcon) layoutIcon = lIcon;
|
||||
if (lNum) layoutNum = lNum;
|
||||
|
||||
struct stat st {};
|
||||
if (::stat(getXresourcesPath().c_str(), &st) == 0) {
|
||||
lastXresMtime = st.st_mtim.tv_sec;
|
||||
lastXresSize = st.st_size;
|
||||
}
|
||||
|
||||
spec = ThemeSpec{};
|
||||
spec.loadActive(dpy, screen);
|
||||
|
||||
if (colorsAllocated) {
|
||||
XftColorFree(dpy, visual, cmap, &colWhite);
|
||||
XftColorFree(dpy, visual, cmap, &colLight);
|
||||
XftColorFree(dpy, visual, cmap, &colMuted);
|
||||
XftColorFree(dpy, visual, cmap, &colYellow);
|
||||
XftColorFree(dpy, visual, cmap, &colGreen);
|
||||
XftColorFree(dpy, visual, cmap, &colBlue);
|
||||
XftColorFree(dpy, visual, cmap, &colOrange);
|
||||
XftColorFree(dpy, visual, cmap, &colRed);
|
||||
}
|
||||
|
||||
allocXft(dpy, visual, cmap, spec.fgBright, &colWhite);
|
||||
allocXft(dpy, visual, cmap, spec.fgMain, &colLight);
|
||||
allocXft(dpy, visual, cmap, spec.fgMuted, &colMuted);
|
||||
allocXft(dpy, visual, cmap, spec.accent, &colYellow);
|
||||
allocXft(dpy, visual, cmap, spec.success, &colGreen);
|
||||
allocXft(dpy, visual, cmap, spec.info, &colBlue);
|
||||
allocXft(dpy, visual, cmap, spec.warning, &colOrange);
|
||||
allocXft(dpy, visual, cmap, spec.danger, &colRed);
|
||||
colorsAllocated = true;
|
||||
|
||||
if (layoutMain) {
|
||||
PangoFontDescription* d =
|
||||
pango_font_description_from_string(spec.pangoMainFontStr().c_str());
|
||||
pango_layout_set_font_description(layoutMain, d);
|
||||
pango_font_description_free(d);
|
||||
}
|
||||
if (layoutSmall) {
|
||||
PangoFontDescription* d =
|
||||
pango_font_description_from_string(spec.pangoSmallFontStr().c_str());
|
||||
pango_layout_set_font_description(layoutSmall, d);
|
||||
pango_font_description_free(d);
|
||||
}
|
||||
if (layoutIcon) {
|
||||
PangoFontDescription* d =
|
||||
pango_font_description_from_string(spec.pangoIconFontStr().c_str());
|
||||
pango_layout_set_font_description(layoutIcon, d);
|
||||
pango_font_description_free(d);
|
||||
}
|
||||
if (layoutNum) {
|
||||
PangoFontDescription* d = pango_font_description_from_string(
|
||||
spec.pangoLargeBoldFontStr().c_str());
|
||||
pango_layout_set_font_description(layoutNum, d);
|
||||
pango_font_description_free(d);
|
||||
}
|
||||
if (win_ != None) {
|
||||
XSetWindowBackground(dpy, win_, spec.bgMain);
|
||||
XSetWindowBorder(dpy, win_, spec.selBg);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkAndReload() {
|
||||
if (!dpy_ || !visual_) return false;
|
||||
return checkAndReload(dpy_, screen_, visual_, cmap_, layoutMain,
|
||||
layoutSmall, layoutIcon, layoutNum, win_);
|
||||
}
|
||||
|
||||
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr,
|
||||
PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr,
|
||||
PangoLayout* lNum = nullptr,
|
||||
Window win = None) {
|
||||
struct stat st {};
|
||||
if (::stat(getXresourcesPath().c_str(), &st) == 0) {
|
||||
if (st.st_mtim.tv_sec != lastXresMtime || st.st_size != lastXresSize) {
|
||||
load(dpy, screen, visual, cmap, lMain, lSmall, lIcon, lNum, win);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace bananarchy
|
||||
#include "../neoui/neoui.h"
|
||||
|
||||
#endif // DWM_PLUGINS_THEME_H
|
||||
@@ -315,55 +315,24 @@ int runThemesApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xthemes", "XThemes", "Themes")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xthemes";
|
||||
char resClass[] = "XThemes";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Themes");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
nullptr, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
@@ -530,20 +499,7 @@ int runThemesApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto drawSwatch = [&](int x, int y, int w, int h, unsigned long color) {
|
||||
@@ -556,28 +512,7 @@ int runThemesApp(int argc, char** argv) {
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, centerLabel.c_str(),
|
||||
static_cast<int>(centerLabel.size()));
|
||||
int cw = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
|
||||
centerLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, rightLabel.c_str(),
|
||||
static_cast<int>(rightLabel.size()));
|
||||
int rw = 0, rhh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawUI = [&]() {
|
||||
|
||||
@@ -221,50 +221,22 @@ int runWallpapersApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xwallpapers", "XWallpapers", "Wallpapers",
|
||||
kWinX, kWinY, kWinWidth, kWinHeight)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec;
|
||||
initSpec.loadActive(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xwallpapers";
|
||||
char resClass[] = "XWallpapers";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Wallpapers");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = neo.layoutMain;
|
||||
auto& layoutSmall = neo.layoutSmall;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
@@ -355,35 +327,13 @@ int runWallpapersApp(int argc, char** argv) {
|
||||
int h, const std::string& text, int maxW = -1,
|
||||
int align = 0) {
|
||||
if (text.empty()) return;
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int tx = x;
|
||||
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
|
||||
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
|
||||
int ty = y + (h - th) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW, align);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& midLabel,
|
||||
const std::string& rightLabel) {
|
||||
int barY = kWinHeight - 24;
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
|
||||
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
|
||||
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
|
||||
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -737,11 +687,6 @@ int runWallpapersApp(int argc, char** argv) {
|
||||
}
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
if (xftDraw) XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+3044
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,575 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// NeoUI - Bananarchy 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
|
||||
// Provides both a C-compatible FFI (libneoui.so) and C++20 SDK classes.
|
||||
// Note: Every extern "C" function returns int, uint32_t, or const char* (never
|
||||
// void) so that FFI callers such as Yabasic frnfn_call / frnfn_call$ work
|
||||
// directly without void-return limitations.
|
||||
|
||||
#ifndef BANANARCHY_NEOUI_H
|
||||
#define BANANARCHY_NEOUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Standard Bananarchy 240x320 QVGA geometry constants
|
||||
enum NeoGeometry {
|
||||
NEO_SCREEN_W = 240,
|
||||
NEO_SCREEN_H = 320,
|
||||
NEO_TOPBAR_H = 24,
|
||||
NEO_WIN_X = 0,
|
||||
NEO_WIN_Y = 24,
|
||||
NEO_WIN_W = 240,
|
||||
NEO_WIN_H = 296,
|
||||
NEO_HEADER_H = 34,
|
||||
NEO_SOFTBAR_H = 26
|
||||
};
|
||||
|
||||
// Theme color token IDs for neoui_color(color_id)
|
||||
enum NeoColorId {
|
||||
NEO_COLOR_BG_MAIN = 0,
|
||||
NEO_COLOR_BG_BAR = 1,
|
||||
NEO_COLOR_BG_HEADER = 2,
|
||||
NEO_COLOR_BG_FOOTER = 3,
|
||||
NEO_COLOR_BG_OVERLAY = 4,
|
||||
NEO_COLOR_BG_ALT_EVEN = 5,
|
||||
NEO_COLOR_BG_ALT_ODD = 6,
|
||||
NEO_COLOR_BG_INPUT = 7,
|
||||
NEO_COLOR_BG_INPUT_FOCUS = 8,
|
||||
NEO_COLOR_BG_BUTTON = 9,
|
||||
NEO_COLOR_BG_SEARCH = 10,
|
||||
NEO_COLOR_BG_BUBBLE_IN = 11,
|
||||
NEO_COLOR_BG_BUBBLE_OUT = 12,
|
||||
NEO_COLOR_BG_TOAST = 13,
|
||||
NEO_COLOR_FG_MAIN = 14,
|
||||
NEO_COLOR_FG_BRIGHT = 15,
|
||||
NEO_COLOR_FG_MUTED = 16,
|
||||
NEO_COLOR_SEL_BG = 17,
|
||||
NEO_COLOR_SEL_FG = 18,
|
||||
NEO_COLOR_ACCENT = 19,
|
||||
NEO_COLOR_ACCENT_ALT = 20,
|
||||
NEO_COLOR_HIGHLIGHT = 21,
|
||||
NEO_COLOR_BORDER = 22,
|
||||
NEO_COLOR_DIVIDER = 23,
|
||||
NEO_COLOR_SUCCESS = 24,
|
||||
NEO_COLOR_INFO = 25,
|
||||
NEO_COLOR_WARNING = 26,
|
||||
NEO_COLOR_DANGER = 27,
|
||||
NEO_COLOR_DANGER_BG = 28
|
||||
};
|
||||
|
||||
// Proportional Pango font roles
|
||||
enum NeoFontRole {
|
||||
NEO_FONT_SMALL = 0,
|
||||
NEO_FONT_MAIN = 1,
|
||||
NEO_FONT_ICON = 2,
|
||||
NEO_FONT_LARGE = 3
|
||||
};
|
||||
|
||||
// Semantic Xft text color roles
|
||||
enum NeoTextColor {
|
||||
NEO_TEXT_WHITE = 0,
|
||||
NEO_TEXT_LIGHT = 1,
|
||||
NEO_TEXT_MUTED = 2,
|
||||
NEO_TEXT_YELLOW = 3,
|
||||
NEO_TEXT_GREEN = 4,
|
||||
NEO_TEXT_BLUE = 5,
|
||||
NEO_TEXT_ORANGE = 6,
|
||||
NEO_TEXT_RED = 7
|
||||
};
|
||||
|
||||
// Event types returned by neoui_poll_event(timeout_ms)
|
||||
enum NeoEventType {
|
||||
NEO_EV_NONE = 0,
|
||||
NEO_EV_EXPOSE = 1,
|
||||
NEO_EV_KEY_PRESS = 2,
|
||||
NEO_EV_KEY_RELEASE = 3,
|
||||
NEO_EV_SOFTKEY_LEFT = 4,
|
||||
NEO_EV_SOFTKEY_RIGHT = 5,
|
||||
NEO_EV_SOFTKEY_CHORD = 6,
|
||||
NEO_EV_FIFO_CMD = 7,
|
||||
NEO_EV_THEME_RELOAD = 8,
|
||||
NEO_EV_CLOSE_REQ = 9
|
||||
};
|
||||
|
||||
// Logical keypad key codes returned by neoui_event_key()
|
||||
enum NeoKey {
|
||||
NEO_KEY_NONE = 0,
|
||||
NEO_KEY_UP = 1,
|
||||
NEO_KEY_DOWN = 2,
|
||||
NEO_KEY_LEFT = 3,
|
||||
NEO_KEY_RIGHT = 4,
|
||||
NEO_KEY_OK = 5,
|
||||
NEO_KEY_BACK = 6,
|
||||
NEO_KEY_CALL = 7,
|
||||
NEO_KEY_END = 8,
|
||||
NEO_KEY_SOFT_LEFT = 9,
|
||||
NEO_KEY_SOFT_RIGHT = 10,
|
||||
NEO_KEY_SPACE = 32,
|
||||
NEO_KEY_HASH = 35,
|
||||
NEO_KEY_STAR = 42,
|
||||
NEO_KEY_PLUS = 43,
|
||||
NEO_KEY_0 = 48,
|
||||
NEO_KEY_1 = 49,
|
||||
NEO_KEY_2 = 50,
|
||||
NEO_KEY_3 = 51,
|
||||
NEO_KEY_4 = 52,
|
||||
NEO_KEY_5 = 53,
|
||||
NEO_KEY_6 = 54,
|
||||
NEO_KEY_7 = 55,
|
||||
NEO_KEY_8 = 56,
|
||||
NEO_KEY_9 = 57
|
||||
};
|
||||
|
||||
// Multi-tap input modes
|
||||
enum NeoInputMode {
|
||||
NEO_INPUT_ABC_TITLE = 0,
|
||||
NEO_INPUT_ABC_LOWER = 1,
|
||||
NEO_INPUT_ABC_UPPER = 2,
|
||||
NEO_INPUT_123 = 3,
|
||||
NEO_INPUT_SYM = 4
|
||||
};
|
||||
|
||||
// Image scaling modes for neoui_draw_image_file
|
||||
enum NeoScaleMode {
|
||||
NEO_SCALE_FIT = 0,
|
||||
NEO_SCALE_FILL = 1,
|
||||
NEO_SCALE_STRETCH = 2
|
||||
};
|
||||
|
||||
// Opaque C context handle
|
||||
typedef struct NeoContext NeoContext;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. Window & Daemon Lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_init(const char* app_name, int preload_mode);
|
||||
int neoui_init_ex(const char* app_name, const char* res_name,
|
||||
const char* res_class, const char* win_title,
|
||||
int x, int y, int w, int h,
|
||||
int override_redirect, int preload_mode);
|
||||
int neoui_shutdown(void);
|
||||
|
||||
int neoui_show(void);
|
||||
int neoui_hide(void);
|
||||
int neoui_is_visible(void);
|
||||
int neoui_raise_and_grab(void);
|
||||
int neoui_ungrab(void);
|
||||
|
||||
int neoui_width(void);
|
||||
int neoui_height(void);
|
||||
|
||||
int neoui_begin_frame(void);
|
||||
int neoui_end_frame(void);
|
||||
int neoui_flush(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 2. Unified .Xresources / .xth Theme & Icon Resolution
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_reload_theme(void);
|
||||
int neoui_check_reload_theme(void);
|
||||
int neoui_apply_theme_file(const char* xth_path);
|
||||
int neoui_broadcast_theme_reload(const char* skip_plugin);
|
||||
|
||||
const char* neoui_theme_name(void);
|
||||
const char* neoui_font_face(void);
|
||||
const char* neoui_icon_font_face(void);
|
||||
int neoui_base_font_size(void);
|
||||
int neoui_font_size(int font_role);
|
||||
|
||||
uint32_t neoui_color(int color_id);
|
||||
uint32_t neoui_adjust_rgb(uint32_t rgb, int delta);
|
||||
uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct);
|
||||
uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb);
|
||||
const char* neoui_format_hex_rgb(uint32_t rgb);
|
||||
const char* neoui_icon(const char* icon_name);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 3. Drawing Primitives & Text Rendering
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_clear(uint32_t rgb);
|
||||
int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb);
|
||||
int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb);
|
||||
int neoui_set_clip(int x, int y, int w, int h);
|
||||
int neoui_reset_clip(void);
|
||||
|
||||
int neoui_draw_text(int font_role, int color_role, int x, int y, int h,
|
||||
const char* text, int max_w);
|
||||
int neoui_draw_text_centered(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text);
|
||||
int neoui_draw_text_right(int font_role, int color_role, int right_x, int y,
|
||||
int h, const char* text, int max_w);
|
||||
int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y,
|
||||
int w, int h, const char* text, int scroll_line);
|
||||
int neoui_text_width(int font_role, const char* text);
|
||||
const char* neoui_tail_fit_text(int font_role, const char* text, int max_w);
|
||||
|
||||
int neoui_draw_image_file(const char* path, int x, int y, int w, int h,
|
||||
int scale_mode);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 4. Standardized OS Shell UI Components (Widgets)
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_draw_header(const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* right_badge);
|
||||
int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role,
|
||||
const char* title, int title_color_role,
|
||||
const char* right_badge, int right_color_role);
|
||||
|
||||
int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h);
|
||||
|
||||
int neoui_draw_softkeys(const char* left_label, const char* center_label,
|
||||
const char* right_label);
|
||||
int neoui_draw_softkeys_ex(const char* left_label, const char* center_label,
|
||||
const char* right_label, int center_color_role);
|
||||
|
||||
int neoui_draw_list_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* title, const char* subtitle,
|
||||
const char* right_text);
|
||||
|
||||
int neoui_draw_slider_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int pct, const char* value_text);
|
||||
|
||||
int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected,
|
||||
const char* icon_str, int icon_color_role,
|
||||
const char* label, int is_on,
|
||||
const char* state_text);
|
||||
|
||||
int neoui_draw_button(int x, int y, int w, int h, int is_selected,
|
||||
int is_danger, const char* icon_str, const char* label);
|
||||
|
||||
int neoui_draw_input_box(int x, int y, int w, int h, int is_focused,
|
||||
const char* label, const char* value,
|
||||
const char* placeholder, int password_mask);
|
||||
|
||||
int neoui_draw_progress_bar(int x, int y, int w, int h, int pct,
|
||||
uint32_t fill_rgb);
|
||||
|
||||
int neoui_draw_scrollbar(int x, int y, int h, int total_items,
|
||||
int visible_items, int scroll_offset);
|
||||
|
||||
int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str,
|
||||
int icon_color_role, const char* title);
|
||||
|
||||
int neoui_draw_confirm_dialog(const char* title, const char* line1,
|
||||
const char* line2, const char* no_label,
|
||||
const char* yes_label, int selected_yes);
|
||||
|
||||
int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons,
|
||||
int selected_idx, int max_visible_rows);
|
||||
|
||||
int neoui_draw_toast(const char* message);
|
||||
int neoui_show_toast(const char* message, int duration_ms);
|
||||
int neoui_clear_toast(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 5. Event Loop, Keypad & Multi-Tap Input Management
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_poll_event(int timeout_ms);
|
||||
int neoui_event_key(void);
|
||||
int neoui_event_keycode(void);
|
||||
int neoui_event_keysym(void);
|
||||
const char* neoui_event_command(void);
|
||||
int neoui_set_chord_xdrawer(int enabled);
|
||||
|
||||
int neoui_input_reset(const char* initial_text);
|
||||
int neoui_input_set_text(const char* text);
|
||||
const char* neoui_input_get_text(void);
|
||||
int neoui_input_set_mode(int mode);
|
||||
int neoui_input_get_mode(void);
|
||||
int neoui_input_cycle_mode(void);
|
||||
const char* neoui_input_mode_badge(void);
|
||||
int neoui_input_feed_key(int neo_key);
|
||||
int neoui_input_commit_tap(void);
|
||||
int neoui_input_backspace(void);
|
||||
int neoui_input_is_tap_active(void);
|
||||
const char* neoui_input_candidate_bar(const char* idle_hint);
|
||||
int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 6. System & IPC Utilities
|
||||
// ---------------------------------------------------------------------------
|
||||
int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd);
|
||||
int neoui_vibrate(int duration_ms);
|
||||
int neoui_now_ms(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
namespace bananarchy {
|
||||
|
||||
std::string themeTrim(const std::string& s);
|
||||
int themeHexNibble(char c);
|
||||
bool parseHexRgb(const std::string& raw, uint32_t* outRgb);
|
||||
std::string formatHexRgb(uint32_t rgb);
|
||||
uint32_t adjustRgb(uint32_t rgb, int delta);
|
||||
uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct);
|
||||
std::string getHomeDirPath();
|
||||
std::string getXresourcesPath();
|
||||
std::string getThemesDirPath();
|
||||
|
||||
struct ThemeSpec {
|
||||
std::string name = "Default";
|
||||
std::string fontFace = "Fira Code";
|
||||
std::string iconFontFace = "DejaVuSansM Nerd Font";
|
||||
int baseFontSize = 15;
|
||||
|
||||
uint32_t bgMain = 0x222222;
|
||||
uint32_t bgBar = 0x222222;
|
||||
uint32_t bgHeader = 0x1c1c1c;
|
||||
uint32_t bgFooter = 0x181818;
|
||||
uint32_t bgOverlay = 0x161616;
|
||||
uint32_t bgAltEven = 0x282828;
|
||||
uint32_t bgAltOdd = 0x2e2e2e;
|
||||
uint32_t bgInput = 0x1a1a1a;
|
||||
uint32_t bgInputFocus = 0x1b3b4b;
|
||||
uint32_t bgButton = 0x2a2a2a;
|
||||
uint32_t bgSearch = 0x383838;
|
||||
uint32_t bgBubbleIn = 0x262d32;
|
||||
uint32_t bgBubbleOut = 0x1f2d38;
|
||||
uint32_t bgToast = 0x102535;
|
||||
|
||||
uint32_t fgMain = 0xdddddd;
|
||||
uint32_t fgBright = 0xffffff;
|
||||
uint32_t fgMuted = 0x999999;
|
||||
|
||||
uint32_t selBg = 0x005577;
|
||||
uint32_t selFg = 0xffffff;
|
||||
uint32_t accent = 0xf4d03f;
|
||||
uint32_t accentAlt = 0x0088bb;
|
||||
uint32_t highlight = 0xffc978;
|
||||
uint32_t border = 0x444444;
|
||||
uint32_t divider = 0x666666;
|
||||
|
||||
uint32_t success = 0x2ecc71;
|
||||
uint32_t info = 0x5dade2;
|
||||
uint32_t warning = 0xe67e22;
|
||||
uint32_t danger = 0xe74c3c;
|
||||
uint32_t dangerBg = 0x922b21;
|
||||
|
||||
int sizeSmall() const;
|
||||
int sizeMain() const;
|
||||
int sizeIcon() const;
|
||||
int sizeLarge() const;
|
||||
|
||||
std::string pangoMainFontStr() const;
|
||||
std::string pangoSmallFontStr() const;
|
||||
std::string pangoIconFontStr() const;
|
||||
std::string pangoLargeBoldFontStr() const;
|
||||
std::string xftFontStr(int pxSize) const;
|
||||
std::string xftIconFontStr(int pxSize) const;
|
||||
|
||||
void recomputeDerivedFromCore();
|
||||
void parseFromMap(const std::unordered_map<std::string, std::string>& kv);
|
||||
static void parseLinesIntoMap(
|
||||
const std::string& content,
|
||||
std::unordered_map<std::string, std::string>& kv);
|
||||
bool loadFromFile(const std::string& path);
|
||||
void loadActive(Display* dpy, int screen);
|
||||
std::string serializeXresources() const;
|
||||
bool saveToFile(const std::string& path) const;
|
||||
uint32_t colorById(int colorId) const;
|
||||
};
|
||||
|
||||
ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0);
|
||||
|
||||
struct PluginTheme {
|
||||
ThemeSpec spec;
|
||||
time_t lastXresMtime = -1;
|
||||
off_t lastXresSize = -1;
|
||||
bool colorsAllocated = false;
|
||||
|
||||
Display* dpy_ = nullptr;
|
||||
int screen_ = 0;
|
||||
Visual* visual_ = nullptr;
|
||||
Colormap cmap_ = 0;
|
||||
Window win_ = None;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
|
||||
XftColor colWhite{};
|
||||
XftColor colLight{};
|
||||
XftColor colMuted{};
|
||||
XftColor colYellow{};
|
||||
XftColor colGreen{};
|
||||
XftColor colBlue{};
|
||||
XftColor colOrange{};
|
||||
XftColor colRed{};
|
||||
|
||||
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
|
||||
XftColor* dst);
|
||||
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
Window win = None);
|
||||
void reload();
|
||||
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr, PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr, PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
bool checkAndReload();
|
||||
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
|
||||
PangoLayout* lMain = nullptr,
|
||||
PangoLayout* lSmall = nullptr,
|
||||
PangoLayout* lIcon = nullptr,
|
||||
PangoLayout* lNum = nullptr,
|
||||
Window win = None);
|
||||
XftColor* colorByRole(int role);
|
||||
PangoLayout* layoutByRole(int role);
|
||||
};
|
||||
|
||||
// Shared Pango rendering & layout helpers in libneoui.so
|
||||
int neoDrawPango(XftDraw* xftDraw, PangoLayout* layout, XftColor* color,
|
||||
int x, int y, int h, const std::string& text,
|
||||
int maxW = -1, int align = 0);
|
||||
int neoPangoWidth(PangoLayout* layout, const std::string& text);
|
||||
void neoDrawSoftbar(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel,
|
||||
XftColor* centerCol = nullptr);
|
||||
void neoDrawScrollbar(Display* dpy, Pixmap pix, GC gc, const PluginTheme& theme,
|
||||
int x, int y, int h, int totalItems, int visibleItems,
|
||||
int scrollOffset);
|
||||
void neoDrawToast(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
|
||||
PluginTheme& theme, int winW, int winH, int softbarH,
|
||||
const std::string& msg);
|
||||
|
||||
std::string formatMultiTapBar(const std::string& prefix, const char* table,
|
||||
int activeIdx, bool makeUpper, int maxItems = 7,
|
||||
size_t maxChars = 21);
|
||||
std::string tailFitPangoText(PangoLayout* layout, const std::string& text,
|
||||
int maxWidthPx);
|
||||
|
||||
// Shared image & media helpers in libneoui.so
|
||||
bool saveRgb24AsJpeg(const std::string& path, const uint8_t* rgb, int width,
|
||||
int height, int quality = 92);
|
||||
bool loadJpegRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadPngRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadFfmpegImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
bool loadImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
|
||||
int* outW, int* outH);
|
||||
void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb, int srcW, int srcH,
|
||||
uint32_t* dstBgrx, int canvasW, int canvasH,
|
||||
uint32_t bgPixel = 0x111111,
|
||||
int scaleMode = NEO_SCALE_FIT);
|
||||
void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
|
||||
uint32_t* dstBgrx,
|
||||
int zoomFactor = 1);
|
||||
std::string formatFileSize(off_t bytes);
|
||||
|
||||
// High-level C++ RAII Window + Theme + Offscreen Pixmap + Pango Context
|
||||
class NeoWindow {
|
||||
public:
|
||||
Display* dpy = nullptr;
|
||||
int screen = 0;
|
||||
Window root = None;
|
||||
Visual* visual = nullptr;
|
||||
Colormap cmap = 0;
|
||||
Window win = None;
|
||||
Pixmap pix = None;
|
||||
GC gc = nullptr;
|
||||
XftDraw* xftDraw = nullptr;
|
||||
PangoContext* pangoCtx = nullptr;
|
||||
PangoLayout* layoutMain = nullptr;
|
||||
PangoLayout* layoutSmall = nullptr;
|
||||
PangoLayout* layoutIcon = nullptr;
|
||||
PangoLayout* layoutNum = nullptr;
|
||||
PluginTheme theme;
|
||||
int x = NEO_WIN_X;
|
||||
int y = NEO_WIN_Y;
|
||||
int width = NEO_WIN_W;
|
||||
int height = NEO_WIN_H;
|
||||
|
||||
NeoWindow() = default;
|
||||
~NeoWindow();
|
||||
|
||||
NeoWindow(const NeoWindow&) = delete;
|
||||
NeoWindow& operator=(const NeoWindow&) = delete;
|
||||
|
||||
bool create(const char* resName, const char* resClass, const char* title,
|
||||
int winX = NEO_WIN_X, int winY = NEO_WIN_Y,
|
||||
int winW = NEO_WIN_W, int winH = NEO_WIN_H,
|
||||
bool overrideRedirect = true,
|
||||
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
ButtonPressMask | VisibilityChangeMask |
|
||||
StructureNotifyMask);
|
||||
void destroy();
|
||||
|
||||
void bindAsActiveContext();
|
||||
|
||||
int drawPango(PangoLayout* layout, XftColor* color, int px, int py, int ph,
|
||||
const std::string& text, int maxW = -1, int align = 0) {
|
||||
return neoDrawPango(xftDraw, layout, color, px, py, ph, text, maxW, align);
|
||||
}
|
||||
|
||||
int pangoWidth(PangoLayout* layout, const std::string& text) {
|
||||
return neoPangoWidth(layout, text);
|
||||
}
|
||||
|
||||
void drawSoftbar(const std::string& leftLabel, const std::string& centerLabel,
|
||||
const std::string& rightLabel, XftColor* centerCol = nullptr,
|
||||
int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawSoftbar(dpy, pix, gc, xftDraw, theme, width, height, softbarH,
|
||||
leftLabel, centerLabel, rightLabel, centerCol);
|
||||
}
|
||||
|
||||
void drawScrollbar(int sx, int sy, int sh, int totalItems, int visibleItems,
|
||||
int scrollOffset) {
|
||||
neoDrawScrollbar(dpy, pix, gc, theme, sx, sy, sh, totalItems, visibleItems,
|
||||
scrollOffset);
|
||||
}
|
||||
|
||||
void drawToast(const std::string& msg, int softbarH = NEO_SOFTBAR_H) {
|
||||
neoDrawToast(dpy, pix, gc, xftDraw, theme, width, height, softbarH, msg);
|
||||
}
|
||||
|
||||
void clearBg() {
|
||||
if (dpy && pix != None && gc) {
|
||||
XSetForeground(dpy, gc, theme.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void present() {
|
||||
if (dpy && pix != None && win != None && gc) {
|
||||
XCopyArea(dpy, pix, win, gc, 0, 0, width, height, 0, 0);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkReloadTheme() {
|
||||
return theme.checkAndReload(dpy, screen, visual, cmap, layoutMain,
|
||||
layoutSmall, layoutIcon, layoutNum, win);
|
||||
}
|
||||
|
||||
void reloadTheme() {
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
layoutNum, win);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace bananarchy
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // BANANARCHY_NEOUI_H
|
||||
+16
-68
@@ -675,51 +675,25 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
bananarchy::NeoWindow neo;
|
||||
if (!neo.create("xdrawer", "XDrawer", "XDrawer", kWinX, kWinY, kWinWidth,
|
||||
kWinHeight, true)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0xf4d03f;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
StructureNotifyMask | VisibilityChangeMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xdrawer";
|
||||
char resClass[] = "XDrawer";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "XDrawer");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
|
||||
bananarchy::PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
nullptr, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
bananarchy::PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -735,27 +709,11 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -1153,16 +1111,6 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(fifoPath.c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user