Add Webarchy ultrawide browser, DNS UI, WLAN/st fixes, and media/CLI packages

- Port Webarchy GTK3/WebKit2GTK browser for 2160x1080 with flush-right vertical tab bar, DPI-scaled .Xresources SIGUSR1 theming, single-instance FIFO, and GPU crash CPU fallback (src/webarchy/webarchy.cpp, geminux-webarchy)
- Cross-compile pure-C gdk-pixbuf 2.42.12 (geminux-gdk-pixbuf) and compile rootfs GSettings schemas so webkit2gtk-4.1 and gst-plugins-good install with zero Rust ELFs
- Add zero-Rust geminux-mpv (mpv v0.40.0, FFmpeg n7.1.5, libplacebo, gst-libav 1.28.9) plus python3, py3-pip, mpg123, yt-dlp (quickjs), gnupg, gpg, pass, and pinentry-curses
- Fix MT6797 WLAN peer deauth and CCMP EAPOL GTK rekey (patch 0007), set wifi.powersave = 2, pin active WLAN connections in geminux-net, and add the DNS tab with geminux-dnsctl
- Restore st filled/hollow cursor focus across screenlock and libgemui grabs via dwm, libgemui, and st updates
- Update README.md, MANUAL.md, ARCHITECTURE.md, POWER-OPTIMIZATION.md, check-rebuild.sh, and host Python tests
This commit is contained in:
Luxferre committed 2026-11-23 12:46:34 +02:00
1 parent c12ed68d19
commit e01806f3c8
82 files changed
+5499 -117

No files matched your search

+418 -60
View File
@@ -2,33 +2,43 @@
#include "gemui.h"
#include "geminux-wifi-list.h"
#include "geminux-bt-list.h"
#include "../geminux-daemons/geminux-dns-valid.h"
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#define HIT_TAB 1
#define HIT_TOGGLE 2
#define HIT_ACTION 3
#define HIT_ROW 4
#define HIT_PSK 5
#define HIT_CONNECT 6
#define HIT_SHOW_PSK 7
#define HIT_BT_CONN 8
#define HIT_BT_DISC 9
#define HIT_BT_REM 10
#define HIT_AUDIO 11
#define HIT_TAB 1
#define HIT_TOGGLE 2
#define HIT_ACTION 3
#define HIT_ROW 4
#define HIT_PSK 5
#define HIT_CONNECT 6
#define HIT_SHOW_PSK 7
#define HIT_BT_CONN 8
#define HIT_BT_DISC 9
#define HIT_BT_REM 10
#define HIT_AUDIO 11
#define HIT_WIFI_DISC 12
#define HIT_DNS_CUSTOM 13
#define HIT_DNS_APPLY 14
enum {
WORK_NONE = 0,
WORK_WIFI_CONN,
WORK_WIFI_SCAN,
WORK_WIFI_DISC,
WORK_DNS_APPLY,
WORK_DNS_TEST,
WORK_BT_PWR,
WORK_BT_SCAN,
WORK_BT_CONN,
@@ -37,19 +47,21 @@ enum {
};
typedef struct {
char col1[96];
char col1[128];
char col2[96];
char col3[48];
} net_row_t;
typedef struct {
gemui_app_t *app;
int tab; /* 0=Wi-Fi, 1=Cellular/4G, 2=Bluetooth, 3=USB/HDMI */
int tab; /* 0=Wi-Fi, 1=DNS, 2=Cellular/4G, 3=Bluetooth, 4=USB/HDMI */
bool wifi_on;
bool wifi_connected;
bool cellular_on;
bool bt_on;
bool bt_svc_up;
bool hdmi_on;
int dns_mode;
net_row_t rows[32];
geminux_wifi_group_t wifi_groups[GEMINUX_MAX_WIFI_GROUPS];
geminux_bt_dev_t bt_devs[GEMINUX_MAX_BT_DEVS];
@@ -58,7 +70,10 @@ typedef struct {
int scroll_off;
char status_text[256];
char psk[128];
char active_dns[128];
char custom_dns[192];
bool focus_psk;
bool focus_dns;
bool show_psk;
pid_t worker_pid;
@@ -79,7 +94,7 @@ static uint64_t net_now_ms(void) {
static int net_visible_rows(const net_state_t *st) {
int h = st->app ? gemui_height(st->app) : 940;
int foot_h = (st->tab == 0 || st->tab == 2) ? 94 : 0;
int foot_h = (st->tab == 0 || st->tab == 1 || st->tab == 3) ? 94 : 0;
int box_h = h - (92 + 82 + 88) - 20 - foot_h;
int vis = (box_h - 8) / 72;
return vis > 0 ? vis : 1;
@@ -96,6 +111,11 @@ static void net_clamp_scroll(net_state_t *st) {
}
}
static void strip_eol(char *s) {
size_t n = strlen(s);
while (n > 0 && (s[n - 1] == '\n' || s[n - 1] == '\r')) s[--n] = '\0';
}
static void refresh_wifi(net_state_t *st, const char *prev_ssid) {
static char out[16384];
out[0] = '\0';
@@ -104,29 +124,190 @@ static void refresh_wifi(net_state_t *st, const char *prev_ssid) {
st->wifi_on = strstr(out, "enabled") != NULL;
}
/* Use cached BSS table so periodic UI redraws never vanish on slow HW rescans. */
out[0] = '\0';
const char *scan[] = {"nmcli", "-t", "-f", "IN-USE,BSSID,SSID,CHAN,SIGNAL,SECURITY", "dev", "wifi", "list", NULL};
if (gemui_run_cmd_timeout(scan, out, sizeof(out), 1200) == 0) {
int ng = geminux_parse_wifi_scan(out, st->wifi_groups, GEMINUX_MAX_WIFI_GROUPS);
st->num_rows = ng;
for (int i = 0; i < ng; i++) {
const geminux_wifi_group_t *g = &st->wifi_groups[i];
net_row_t *r = &st->rows[i];
snprintf(r->col1, sizeof(r->col1), "%s%s", g->in_use ? "* " : "", g->ssid);
if (g->ap_count > 1) {
snprintf(r->col2, sizeof(r->col2), "Mesh (%d) %d%%", g->ap_count, g->best_signal);
} else {
snprintf(r->col2, sizeof(r->col2), "Signal %d%%", g->best_signal);
}
snprintf(r->col3, sizeof(r->col3), "%s", g->security);
if (prev_ssid[0] && strcmp(g->ssid, prev_ssid) == 0) {
st->sel_row = i;
const char *scan[] = {"nmcli", "-t", "-f", "IN-USE,BSSID,SSID,CHAN,SIGNAL,SECURITY",
"dev", "wifi", "list", "--rescan", "no", NULL};
int ng = 0;
if (gemui_run_cmd_timeout(scan, out, sizeof(out), 2000) == 0) {
ng = geminux_parse_wifi_scan(out, st->wifi_groups, GEMINUX_MAX_WIFI_GROUPS);
}
char iw_out[1024] = {0};
char iw_bssid[24] = {0};
char iw_ssid[96] = {0};
int iw_chan = 0, iw_sig = 0;
const char *iw_cmd[] = {"iw", "dev", "wlan0", "link", NULL};
bool iw_ok = (gemui_run_cmd_timeout(iw_cmd, iw_out, sizeof(iw_out), 700) == 0) &&
geminux_parse_iw_link(iw_out, iw_bssid, sizeof(iw_bssid),
iw_ssid, sizeof(iw_ssid), &iw_chan, &iw_sig);
char dev_out[1024] = {0};
bool nm_conn = false;
char nm_con[96] = {0};
char ip4[48] = {0};
const char *dev_cmd[] = {"nmcli", "-t", "-f", "GENERAL.STATE,GENERAL.CONNECTION,IP4.ADDRESS",
"dev", "show", "wlan0", NULL};
if (gemui_run_cmd_timeout(dev_cmd, dev_out, sizeof(dev_out), 900) == 0) {
char *save = NULL;
for (char *ln = strtok_r(dev_out, "\n", &save); ln; ln = strtok_r(NULL, "\n", &save)) {
strip_eol(ln);
char *sep = strchr(ln, ':');
if (!sep) continue;
*sep = '\0';
const char *val = sep + 1;
if (strcmp(ln, "GENERAL.STATE") == 0) {
if (atoi(val) == 100) nm_conn = true;
} else if (strcmp(ln, "GENERAL.CONNECTION") == 0) {
if (val[0] && strcmp(val, "--") != 0) snprintf(nm_con, sizeof(nm_con), "%s", val);
} else if (strncmp(ln, "IP4.ADDRESS", 11) == 0) {
if (val[0] && !ip4[0]) {
snprintf(ip4, sizeof(ip4), "%s", val);
char *slash = strchr(ip4, '/');
if (slash) *slash = '\0';
}
}
}
}
char active_ssid[96] = {0};
if (iw_ssid[0]) {
snprintf(active_ssid, sizeof(active_ssid), "%s", iw_ssid);
} else if (nm_conn && nm_con[0]) {
char nm_ssid[128] = {0};
const char *gs[] = {"nmcli", "-g", "802-11-wireless.ssid",
"connection", "show", "id", nm_con, NULL};
if (gemui_run_cmd_timeout(gs, nm_ssid, sizeof(nm_ssid), 800) == 0) {
strip_eol(nm_ssid);
if (nm_ssid[0]) snprintf(active_ssid, sizeof(active_ssid), "%s", nm_ssid);
}
if (!active_ssid[0]) snprintf(active_ssid, sizeof(active_ssid), "%s", nm_con);
}
char active_sec[48] = {0};
if ((iw_ok || nm_conn) && active_ssid[0]) {
for (int i = 0; i < ng; i++) {
if (strcmp(st->wifi_groups[i].ssid, active_ssid) == 0 &&
st->wifi_groups[i].security[0] &&
strcmp(st->wifi_groups[i].security, "--") != 0) {
snprintf(active_sec, sizeof(active_sec), "%s", st->wifi_groups[i].security);
break;
}
}
if (!active_sec[0] && nm_con[0]) {
char km[64] = {0};
const char *gk[] = {"nmcli", "-g", "802-11-wireless-security.key-mgmt",
"connection", "show", "id", nm_con, NULL};
if (gemui_run_cmd_timeout(gk, km, sizeof(km), 800) == 0) {
strip_eol(km);
if (strcmp(km, "wpa-psk") == 0) snprintf(active_sec, sizeof(active_sec), "WPA2");
else if (strcmp(km, "sae") == 0) snprintf(active_sec, sizeof(active_sec), "WPA3");
else if (!km[0]) snprintf(active_sec, sizeof(active_sec), "Open");
}
}
ng = geminux_merge_active_wifi(st->wifi_groups, ng, GEMINUX_MAX_WIFI_GROUPS,
active_ssid, iw_bssid, iw_chan, iw_sig, active_sec);
}
st->wifi_connected = ((iw_ok || nm_conn) && active_ssid[0] != '\0');
st->num_rows = ng;
for (int i = 0; i < ng; i++) {
const geminux_wifi_group_t *g = &st->wifi_groups[i];
net_row_t *r = &st->rows[i];
snprintf(r->col1, sizeof(r->col1), "%s%s", g->in_use ? "* " : "", g->ssid);
if (g->in_use) {
if (g->ap_count > 1) {
snprintf(r->col2, sizeof(r->col2), "Connected (%d) %d%%", g->ap_count, g->best_signal);
} else if (g->best_signal > 0) {
snprintf(r->col2, sizeof(r->col2), "Connected %d%%", g->best_signal);
} else {
snprintf(r->col2, sizeof(r->col2), "Connected");
}
} else if (g->ap_count > 1) {
snprintf(r->col2, sizeof(r->col2), "Mesh (%d) %d%%", g->ap_count, g->best_signal);
} else {
snprintf(r->col2, sizeof(r->col2), "Signal %d%%", g->best_signal);
}
snprintf(r->col3, sizeof(r->col3), "%s", g->security);
if (prev_ssid && prev_ssid[0] && strcmp(g->ssid, prev_ssid) == 0) {
st->sel_row = i;
} else if ((!prev_ssid || !prev_ssid[0]) && g->in_use && st->sel_row < 0) {
st->sel_row = i;
}
}
net_clamp_scroll(st);
snprintf(st->status_text, sizeof(st->status_text), "Wi-Fi %s (powersave=3)",
st->wifi_on ? "Enabled" : "Disabled");
if (st->wifi_connected) {
if (ip4[0]) {
snprintf(st->status_text, sizeof(st->status_text), "Connected: %s (%s)", active_ssid, ip4);
} else {
snprintf(st->status_text, sizeof(st->status_text), "Connected: %s", active_ssid);
}
} else {
snprintf(st->status_text, sizeof(st->status_text), "Wi-Fi %s (Not connected)",
st->wifi_on ? "Enabled" : "Disabled");
}
}
static void refresh_dns(net_state_t *st) {
int mode = GEMINUX_DNS_DEFAULT;
char saved_custom[192] = {0};
FILE *f = fopen("/etc/geminux/dns.conf", "r");
if (f) {
char line[256];
while (fgets(line, sizeof(line), f)) {
strip_eol(line);
if (strncmp(line, "mode=", 5) == 0) {
int m = geminux_dns_mode_index(line + 5);
if (m >= 0) mode = m;
} else if (strncmp(line, "custom=", 7) == 0) {
snprintf(saved_custom, sizeof(saved_custom), "%s", line + 7);
}
}
fclose(f);
}
st->dns_mode = mode;
if (!st->focus_dns && saved_custom[0]) {
snprintf(st->custom_dns, sizeof(st->custom_dns), "%s", saved_custom);
}
st->active_dns[0] = '\0';
FILE *rf = fopen("/etc/resolv.conf", "r");
if (rf) {
char rbuf[1024];
size_t nr = fread(rbuf, 1, sizeof(rbuf) - 1, rf);
rbuf[nr] = '\0';
fclose(rf);
geminux_parse_resolv_conf(rbuf, st->active_dns, sizeof(st->active_dns));
}
st->num_rows = GEMINUX_DNS_COUNT;
for (int i = 0; i < GEMINUX_DNS_COUNT; i++) {
const geminux_dns_preset_t *p = &GEMINUX_DNS_PRESETS[i];
net_row_t *r = &st->rows[i];
bool act = (i == mode);
if (i == GEMINUX_DNS_DEFAULT) {
snprintf(r->col1, sizeof(r->col1), "%s%s", act ? "* " : "", p->label);
snprintf(r->col2, sizeof(r->col2), "Automatic");
} else if (i == GEMINUX_DNS_CUSTOM) {
const char *shown = st->custom_dns[0] ? st->custom_dns
: (saved_custom[0] ? saved_custom : "Enter below...");
snprintf(r->col1, sizeof(r->col1), "%s%s: %.64s", act ? "* " : "", p->label, shown);
snprintf(r->col2, sizeof(r->col2), "Custom");
} else {
snprintf(r->col1, sizeof(r->col1), "%s%s (%s)", act ? "* " : "", p->label, p->v4_csv);
snprintf(r->col2, sizeof(r->col2), p->v6_csv[0] ? "IPv4 + IPv6" : "IPv4");
}
snprintf(r->col3, sizeof(r->col3), "%s", act ? "Active" : "Select");
}
if (st->focus_dns) st->sel_row = GEMINUX_DNS_CUSTOM;
else st->sel_row = mode;
net_clamp_scroll(st);
snprintf(st->status_text, sizeof(st->status_text), "DNS: %s | resolv.conf: %s",
GEMINUX_DNS_PRESETS[mode].label,
st->active_dns[0] ? st->active_dns : "none");
}
static void refresh_bt(net_state_t *st, const char *prev_mac) {
@@ -192,7 +373,7 @@ static void refresh_tab(net_state_t *st) {
char prev_key[96] = {0};
if (st->tab == 0 && st->sel_row >= 0 && st->sel_row < st->num_rows) {
snprintf(prev_key, sizeof(prev_key), "%s", st->wifi_groups[st->sel_row].ssid);
} else if (st->tab == 2 && st->sel_row >= 0 && st->sel_row < st->num_rows) {
} else if (st->tab == 3 && st->sel_row >= 0 && st->sel_row < st->num_rows) {
snprintf(prev_key, sizeof(prev_key), "%s", st->bt_devs[st->sel_row].mac);
}
@@ -204,6 +385,8 @@ static void refresh_tab(net_state_t *st) {
if (st->tab == 0) {
refresh_wifi(st, prev_key);
} else if (st->tab == 1) {
refresh_dns(st);
} else if (st->tab == 2) {
st->scroll_off = 0;
gemui_unix_cmd("/run/geminux/ccci.sock", "status", out, sizeof(out));
st->cellular_on = strstr(out, "READY") != NULL;
@@ -221,7 +404,7 @@ static void refresh_tab(net_state_t *st) {
st->num_rows++;
}
}
} else if (st->tab == 2) {
} else if (st->tab == 3) {
refresh_bt(st, prev_key);
} else {
st->scroll_off = 0;
@@ -338,6 +521,22 @@ static void on_worker_fd(gemui_app_t *app, int fd, void *ud) {
}
} else if (kind == WORK_WIFI_SCAN) {
gemui_show_toast(app, rc == 0 ? "Wi-Fi scan updated" : "Wi-Fi rescan failed", 1800);
} else if (kind == WORK_WIFI_DISC) {
gemui_show_toast(app, rc == 0 ? "Disconnected Wi-Fi" : "Wi-Fi disconnect failed", 2000);
} else if (kind == WORK_DNS_APPLY) {
if (rc == 0) {
st->focus_dns = false;
gemui_show_toast(app, "DNS settings applied", 2200);
} else {
snprintf(toast, sizeof(toast), err[0] ? "DNS error: %.180s" : "Failed to apply DNS", err);
gemui_show_toast(app, toast, 3200);
}
} else if (kind == WORK_DNS_TEST) {
if (err[0]) {
gemui_show_toast(app, err, 3600);
} else {
gemui_show_toast(app, rc == 0 ? "DNS lookup succeeded" : "DNS lookup failed", 2600);
}
} else if (kind == WORK_BT_PWR) {
if (rc == 0) gemui_show_toast(app, "Updated Bluetooth power", 1800);
else {
@@ -375,7 +574,7 @@ static void on_worker_timer(gemui_app_t *app, void *ud) {
return;
}
st->worker_tick++;
if (st->worker_kind == WORK_BT_SCAN && (st->worker_tick % 4) == 0 && st->tab == 2) {
if (st->worker_kind == WORK_BT_SCAN && (st->worker_tick % 4) == 0 && st->tab == 3) {
char prev_mac[24] = {0};
if (st->sel_row >= 0 && st->sel_row < st->num_rows) {
snprintf(prev_mac, sizeof(prev_mac), "%s", st->bt_devs[st->sel_row].mac);
@@ -467,8 +666,7 @@ static void wifi_delete_ssid_profiles(const char *ssid) {
char p_ssid[128] = {0};
const char *get_ssid[] = {"nmcli", "-g", "802-11-wireless.ssid", "connection", "show", "uuid", uuid, NULL};
if (gemui_run_cmd_timeout(get_ssid, p_ssid, sizeof(p_ssid), 1200) == 0) {
size_t n = strlen(p_ssid);
while (n > 0 && (p_ssid[n - 1] == '\n' || p_ssid[n - 1] == '\r')) p_ssid[--n] = '\0';
strip_eol(p_ssid);
if (strcmp(p_ssid, ssid) == 0) {
const char *del_u[] = {"nmcli", "connection", "delete", "uuid", uuid, NULL};
gemui_run_cmd_timeout(del_u, NULL, 0, 5000);
@@ -531,7 +729,10 @@ static int child_wifi_connect(void *ctx) {
rc = gemui_run_cmd_timeout(up, out, sizeof(out), 22000);
}
}
if (rc != 0 && out[0]) {
if (rc == 0) {
const char *dns_apply[] = {"doas", "/usr/sbin/geminux-dnsctl", "apply", NULL};
gemui_run_cmd_timeout(dns_apply, NULL, 0, 5000);
} else if (out[0]) {
fputs(out, stdout);
}
return rc;
@@ -546,6 +747,58 @@ static int child_wifi_rescan(void *ctx) {
return rc;
}
static int child_wifi_disconnect(void *ctx) {
(void)ctx;
char out[256] = {0};
const char *argv[] = {"nmcli", "device", "disconnect", "wlan0", NULL};
int rc = gemui_run_cmd_timeout(argv, out, sizeof(out), 8000);
if (rc != 0 && out[0]) fputs(out, stdout);
return rc;
}
typedef struct {
int mode;
char custom[192];
} dns_job_t;
static int child_dns_apply(void *ctx) {
dns_job_t *j = ctx;
char out[256] = {0};
const char *mode_str = GEMINUX_DNS_PRESETS[j->mode].mode;
const char *argv_custom[] = {"doas", "/usr/sbin/geminux-dnsctl", "set", mode_str, j->custom, NULL};
const char *argv_preset[] = {"doas", "/usr/sbin/geminux-dnsctl", "set", mode_str, NULL};
int rc = gemui_run_cmd_timeout((j->mode == GEMINUX_DNS_CUSTOM) ? argv_custom : argv_preset,
out, sizeof(out), 8000);
if (rc != 0 && out[0]) fputs(out, stdout);
return rc;
}
static int child_dns_test(void *ctx) {
(void)ctx;
struct timespec t0, t1;
clock_gettime(CLOCK_MONOTONIC, &t0);
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo *res = NULL;
int rc = getaddrinfo("dl-cdn.alpinelinux.org", NULL, &hints, &res);
clock_gettime(CLOCK_MONOTONIC, &t1);
long ms = (long)((t1.tv_sec - t0.tv_sec) * 1000L + (t1.tv_nsec - t0.tv_nsec) / 1000000L);
if (rc != 0 || !res) {
printf("DNS failed (%ld ms): %s\n", ms, gai_strerror(rc));
return 1;
}
char host[64] = {0};
getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST);
freeaddrinfo(res);
printf("DNS OK: alpinelinux -> %s (%ld ms)\n", host[0] ? host : "resolved", ms);
return 0;
}
typedef struct {
char mac[24];
bool enable;
@@ -668,6 +921,50 @@ static void connect_selected_wifi(net_state_t *st) {
memset(&job, 0, sizeof(job));
}
static void disconnect_wifi(net_state_t *st) {
if (!st->wifi_connected) {
gemui_show_toast(st->app, "Wi-Fi is not connected", 1600);
return;
}
start_worker(st, WORK_WIFI_DISC, "Disconnecting Wi-Fi...", 10000, child_wifi_disconnect, NULL);
}
static void apply_dns_mode(net_state_t *st, int mode) {
if (mode < 0 || mode >= GEMINUX_DNS_COUNT) {
gemui_show_toast(st->app, "Select a DNS profile first", 1600);
return;
}
dns_job_t job;
memset(&job, 0, sizeof(job));
job.mode = mode;
if (mode == GEMINUX_DNS_CUSTOM) {
char v4[GEMINUX_DNS_MAX_SERVERS][16];
char v6[GEMINUX_DNS_MAX_SERVERS][46];
int n4 = 0, n6 = 0;
char norm[192] = {0};
if (geminux_parse_dns_servers(st->custom_dns, v4, &n4, GEMINUX_DNS_MAX_SERVERS,
v6, &n6, GEMINUX_DNS_MAX_SERVERS,
norm, sizeof(norm)) <= 0) {
gemui_show_toast(st->app, "Enter valid comma/space IPv4 or IPv6 nameservers", 2600);
st->focus_dns = true;
st->sel_row = GEMINUX_DNS_CUSTOM;
gemui_request_redraw(st->app);
return;
}
snprintf(st->custom_dns, sizeof(st->custom_dns), "%s", norm);
snprintf(job.custom, sizeof(job.custom), "%s", norm);
}
start_worker(st, WORK_DNS_APPLY, "Applying DNS configuration...", 10000, child_dns_apply, &job);
}
static void apply_selected_dns(net_state_t *st) {
int mode = st->focus_dns ? GEMINUX_DNS_CUSTOM : st->sel_row;
apply_dns_mode(st, mode);
}
static void start_bt_dev_action(net_state_t *st, int kind) {
if (st->sel_row < 0 || st->sel_row >= st->num_rows) {
gemui_show_toast(st->app, "Select a Bluetooth device first", 1600);
@@ -701,9 +998,9 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
int pad = 20;
int top = 92;
int tab_w = (w - pad * 2 - 3 * 12) / 4;
static const char *tabs[4] = {"Wi-Fi", "4G / CCCI", "Bluetooth", "USB & HDMI"};
for (int i = 0; i < 4; i++) {
int tab_w = (w - pad * 2 - 4 * 12) / 5;
static const char *tabs[5] = {"Wi-Fi", "DNS", "4G / CCCI", "Bluetooth", "USB & HDMI"};
for (int i = 0; i < 5; i++) {
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (tab_w + 12), top, tab_w, 66},
tabs[i], HIT_TAB, i, false, st->tab == i, false);
}
@@ -717,31 +1014,38 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
act_lbl, HIT_ACTION, 0, st->worker_pid == 0, st->worker_pid > 0, false);
} else if (st->tab == 1) {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"MT6797 Modem Active", st->cellular_on, HIT_TOGGLE, 1, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"Reset to Router DNS", HIT_TOGGLE, 1,
false, st->dns_mode == GEMINUX_DNS_DEFAULT, false);
const char *dns_act = (st->worker_pid > 0) ? "Cancel Operation" : "Test DNS Lookup";
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
"Reset CCCI Modem", HIT_ACTION, 1, false, false, false);
dns_act, HIT_ACTION, 1, st->worker_pid == 0, st->worker_pid > 0, false);
} else if (st->tab == 2) {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"Bluetooth Radio", st->bt_on, HIT_TOGGLE, 2, false);
"MT6797 Modem Active", st->cellular_on, HIT_TOGGLE, 2, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
"Reset CCCI Modem", HIT_ACTION, 2, false, false, false);
} else if (st->tab == 3) {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"Bluetooth Radio", st->bt_on, HIT_TOGGLE, 3, false);
const char *bt_lbl = (st->worker_kind == WORK_BT_SCAN) ? "Stop Scan"
: (st->worker_pid > 0) ? "Cancel Operation" : "Scan 12s";
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
bt_lbl, HIT_ACTION, 2, st->worker_pid == 0, st->worker_pid > 0, false);
bt_lbl, HIT_ACTION, 3, st->worker_pid == 0, st->worker_pid > 0, false);
} else {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"SiI9024 HDMI Extend", st->hdmi_on, HIT_TOGGLE, 3, false);
"SiI9024 HDMI Extend", st->hdmi_on, HIT_TOGGLE, 4, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
"Mirror Primary Display", HIT_ACTION, 3, true, false, false);
"Mirror Primary Display", HIT_ACTION, 4, true, false, false);
}
int foot_h = (st->tab == 0 || st->tab == 2) ? 94 : 0;
int foot_h = (st->tab == 0 || st->tab == 1 || st->tab == 3) ? 94 : 0;
gemui_rect_t box = {pad, cy + 88, w - pad * 2, h - (cy + 88) - pad - foot_h};
gemui_fill_round(cr, box, 12, t->bg_bar);
gemui_stroke_round(cr, box, 12, 1.5, t->border);
if (st->num_rows == 0) {
const char *empty_msg = (st->tab == 2 && st->bt_svc_up)
const char *empty_msg = (st->tab == 3 && st->bt_svc_up)
? "No Bluetooth devices found — press Scan 12s"
: "No interfaces or scan results available";
gemui_draw_text(cr, t, box, empty_msg, 0, false, GEMUI_ALIGN_CENTER, t->fg_muted);
@@ -767,18 +1071,29 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
}
if (st->tab == 0) {
int cw = 260;
int sw = 200;
int iw = w - pad * 2 - cw - sw - 24;
int cw = 250;
int dw = 210;
int sw = 180;
int iw = w - pad * 2 - cw - dw - sw - 36;
gemui_draw_input(app, cr, (gemui_rect_t){pad, h - 92, iw, 72},
"Wi-Fi passphrase (if connecting to secured SSID)...",
st->psk, !st->show_psk, st->focus_psk, HIT_PSK, 0);
gemui_draw_button(app, cr, (gemui_rect_t){pad + iw + 12, h - 92, sw, 72},
st->show_psk ? "Hide PW" : "Show PW", HIT_SHOW_PSK, 0,
false, st->show_psk, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + iw + sw + 24, h - 92, dw, 72},
"Disconnect", HIT_WIFI_DISC, 0, false, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){w - pad - cw, h - 92, cw, 72},
"Connect Wi-Fi", HIT_CONNECT, 0, true, false, false);
} else if (st->tab == 2) {
} else if (st->tab == 1) {
int aw = 290;
int iw = w - pad * 2 - aw - 12;
gemui_draw_input(app, cr, (gemui_rect_t){pad, h - 92, iw, 72},
"Custom nameservers (e.g. 88.198.92.222, 1.1.1.1)...",
st->custom_dns, false, st->focus_dns, HIT_DNS_CUSTOM, 0);
gemui_draw_button(app, cr, (gemui_rect_t){w - pad - aw, h - 92, aw, 72},
"Apply DNS Profile", HIT_DNS_APPLY, 0, true, false, false);
} else if (st->tab == 3) {
int bw = (w - pad * 2 - 3 * 12) / 4;
gemui_draw_button(app, cr, (gemui_rect_t){pad, h - 92, bw, 72},
"Pair & Connect", HIT_BT_CONN, 0, true, false, false);
@@ -796,29 +1111,43 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
if (ks == XK_Escape) {
gemui_quit(app, 0);
} else if (ks == XK_Tab) {
st->tab = (st->tab + 1) % 4;
st->tab = (st->tab + 1) % 5;
st->focus_psk = false;
st->focus_dns = false;
refresh_tab(st);
gemui_request_redraw(app);
} else if (ks == XK_Up && st->num_rows > 0) {
st->sel_row = (st->sel_row > 0) ? st->sel_row - 1 : 0;
if (st->tab == 1) st->focus_dns = (st->sel_row == GEMINUX_DNS_CUSTOM);
net_clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Down && st->num_rows > 0) {
st->sel_row = (st->sel_row + 1 < st->num_rows) ? st->sel_row + 1 : st->num_rows - 1;
if (st->tab == 1) st->focus_dns = (st->sel_row == GEMINUX_DNS_CUSTOM);
net_clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Return || ks == XK_KP_Enter) {
if (st->tab == 0) connect_selected_wifi(st);
else if (st->tab == 2) start_bt_dev_action(st, WORK_BT_CONN);
else if (st->tab == 1) apply_selected_dns(st);
else if (st->tab == 3) start_bt_dev_action(st, WORK_BT_CONN);
} else if ((ks == XK_BackSpace || ks == XK_Delete) && st->tab == 0 && (st->focus_psk || st->sel_row >= 0)) {
st->focus_psk = true;
gemui_utf8_pop_char(st->psk);
gemui_request_redraw(app);
} else if ((ks == XK_BackSpace || ks == XK_Delete) && st->tab == 1 && (st->focus_dns || st->sel_row == GEMINUX_DNS_CUSTOM)) {
st->focus_dns = true;
st->sel_row = GEMINUX_DNS_CUSTOM;
gemui_utf8_pop_char(st->custom_dns);
gemui_request_redraw(app);
} else if ((state & ControlMask) && (ks == XK_u || ks == XK_U) && st->tab == 0) {
st->focus_psk = true;
memset(st->psk, 0, sizeof(st->psk));
gemui_request_redraw(app);
} else if ((state & ControlMask) && (ks == XK_u || ks == XK_U) && st->tab == 1) {
st->focus_dns = true;
st->sel_row = GEMINUX_DNS_CUSTOM;
memset(st->custom_dns, 0, sizeof(st->custom_dns));
gemui_request_redraw(app);
} else if (st->tab == 0 && (st->focus_psk || st->sel_row >= 0) && utf8 && utf8[0]) {
st->focus_psk = true;
size_t cur = strlen(st->psk), add = strlen(utf8);
@@ -826,6 +1155,14 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
memcpy(st->psk + cur, utf8, add + 1);
gemui_request_redraw(app);
}
} else if (st->tab == 1 && (st->focus_dns || st->sel_row == GEMINUX_DNS_CUSTOM) && utf8 && utf8[0]) {
st->focus_dns = true;
st->sel_row = GEMINUX_DNS_CUSTOM;
size_t cur = strlen(st->custom_dns), add = strlen(utf8);
if (cur + add < sizeof(st->custom_dns)) {
memcpy(st->custom_dns + cur, utf8, add + 1);
gemui_request_redraw(app);
}
}
}
@@ -852,18 +1189,29 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
if (hit->id == HIT_TAB) {
st->tab = hit->val;
st->focus_psk = false;
st->focus_dns = false;
refresh_tab(st);
} else if (hit->id == HIT_ROW) {
st->sel_row = hit->val;
if (st->tab == 0) st->focus_psk = true;
else if (st->tab == 1) st->focus_dns = (hit->val == GEMINUX_DNS_CUSTOM);
} else if (hit->id == HIT_PSK) {
st->focus_psk = true;
} else if (hit->id == HIT_SHOW_PSK) {
st->show_psk = !st->show_psk;
st->focus_psk = true;
} else if (hit->id == HIT_WIFI_DISC) {
disconnect_wifi(st);
return;
} else if (hit->id == HIT_CONNECT) {
connect_selected_wifi(st);
return;
} else if (hit->id == HIT_DNS_CUSTOM) {
st->focus_dns = true;
st->sel_row = GEMINUX_DNS_CUSTOM;
} else if (hit->id == HIT_DNS_APPLY) {
apply_selected_dns(st);
return;
} else if (hit->id == HIT_BT_CONN) {
start_bt_dev_action(st, WORK_BT_CONN);
return;
@@ -883,10 +1231,13 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
gemui_run_cmd_timeout(argv, NULL, 0, 2000);
refresh_tab(st);
} else if (hit->val == 1) {
apply_dns_mode(st, GEMINUX_DNS_DEFAULT);
return;
} else if (hit->val == 2) {
gemui_unix_cmd("/run/geminux/ccci.sock",
st->cellular_on ? "flight on" : "flight off", NULL, 0);
refresh_tab(st);
} else if (hit->val == 2) {
} else if (hit->val == 3) {
bt_job_t job;
memset(&job, 0, sizeof(job));
job.enable = !st->bt_on;
@@ -894,7 +1245,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
job.enable ? "Enabling Bluetooth..." : "Disabling Bluetooth...",
10000, child_bt_power, &job);
return;
} else if (hit->val == 3) {
} else if (hit->val == 4) {
const char *argv[] = {"xrandr", "--output", "HDMI-1", st->hdmi_on ? "--off" : "--auto", NULL};
gemui_run_cmd_timeout(argv, NULL, 0, 2000);
st->hdmi_on = !st->hdmi_on;
@@ -909,17 +1260,24 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
}
return;
} else if (hit->val == 1) {
if (st->worker_pid > 0) {
cancel_worker(st, "Cancelled operation");
} else {
start_worker(st, WORK_DNS_TEST, "Testing DNS lookup...", 8000, child_dns_test, NULL);
}
return;
} else if (hit->val == 2) {
gemui_unix_cmd("/run/geminux/ccci.sock", "reset", NULL, 0);
gemui_show_toast(app, "Sent CCCI reset request", 1600);
refresh_tab(st);
} else if (hit->val == 2) {
} else if (hit->val == 3) {
if (st->worker_pid > 0) {
cancel_worker(st, st->worker_kind == WORK_BT_SCAN ? "Bluetooth scan stopped" : "Cancelled");
} else {
start_worker(st, WORK_BT_SCAN, "Scanning Bluetooth (12s)...", 15000, child_bt_scan, NULL);
}
return;
} else if (hit->val == 3) {
} else if (hit->val == 4) {
const char *argv[] = {"xrandr", "--output", "HDMI-1", "--same-as", "DSI-1", NULL};
gemui_run_cmd_timeout(argv, NULL, 0, 2000);
refresh_tab(st);