games: auto-size windows to available screen; dmenu shows Sys menu from any app

This commit is contained in:
Luxferre
2026-10-23 18:50:12 +03:00
parent 2a12f8bdb4
commit 313e137d87
9 changed files with 24 additions and 18 deletions
+10 -5
View File
@@ -22,8 +22,7 @@
#include <X11/keysym.h>
#include <X11/Xatom.h>
static const int WIN_W = 220;
static const int WIN_H = 268;
static const int TOPBAR = 24;
static const int COLS = 24;
static const int ROWS = 28;
@@ -86,8 +85,8 @@ static Window win;
static GC gc;
static Pixmap back;
static int screen;
static int winW = WIN_W, winH = WIN_H;
static int cell, gx0, gy0, gw, gh;
static int winW = 240, winH = 296; // overridden at runtime from the actual screen
// ---- colors (Nokia green monochrome) ----
static unsigned long C_BG, C_FG, C_HEAD, C_FOOD, C_DIM;
@@ -215,9 +214,9 @@ static void render() {
XFillRectangle(dpy, back, gc, 0, 0, winW, winH);
// playfield border (single clean frame around the grid)
// border framing the whole window (adapts to the actual screen size)
XSetForeground(dpy, gc, C_DIM);
XDrawRectangle(dpy, back, gc, gx0 - 1, gy0 - 1, gw + 2, gh + 2);
XDrawRectangle(dpy, back, gc, 2, 2, winW - 4, winH - 4);
// food
if (foodx >= 0) {
XSetForeground(dpy, gc, C_FOOD);
@@ -286,6 +285,12 @@ static void setup_window() {
dpy = XOpenDisplay(nullptr);
if (!dpy) { fprintf(stderr, "snake: cannot open display\n"); exit(1); }
screen = DefaultScreen(dpy);
int sw = DisplayWidth(dpy, screen);
int scrH = DisplayHeight(dpy, screen);
winW = sw;
winH = scrH - TOPBAR; // fill the area below the status bar
if (winW < 96) winW = 96;
if (winH < 96) winH = 96;
win = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, winW, winH, 0,
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
XStoreName(dpy, win, "Snake");
+8 -3
View File
@@ -23,8 +23,7 @@
#include <X11/keysym.h>
#include <X11/Xatom.h>
static const int WIN_W = 224;
static const int WIN_H = 292;
static const int TOPBAR = 24;
static const int PCOLS = 10;
static const int PROWS = 20;
static const int CELL = 14;
@@ -87,7 +86,7 @@ static Window win;
static GC gc;
static Pixmap back;
static int screen;
static int winW = WIN_W, winH = WIN_H;
static int winW = 240, winH = 296; // overridden at runtime from the actual screen
static unsigned long C_BG, C_FG, C_HEAD, C_FOOD, C_DIM;
// ---- tetromino definitions (state 0 within a 4x4 box) ----
@@ -328,6 +327,12 @@ static void setup_window() {
dpy = XOpenDisplay(nullptr);
if (!dpy) { fprintf(stderr, "tetris: cannot open display\n"); exit(1); }
screen = DefaultScreen(dpy);
int sw = DisplayWidth(dpy, screen);
int scrH = DisplayHeight(dpy, screen);
winW = sw;
winH = scrH - TOPBAR; // fill the area below the status bar
if (winW < 96) winW = 96;
if (winH < 96) winH = 96;
win = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, winW, winH, 0,
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
XStoreName(dpy, win, "Tetris");
+6 -10
View File
@@ -1649,16 +1649,12 @@ open_builtin_menu(const char *menu_name, int keep_idx)
if (!cls[0] || strcmp(cls, "sys") == 0) {
menu_name = "sys";
} else if (strcmp(cls, "st") == 0 || strncmp(cls, "st-", 3) == 0) {
if (strstr(ttl, "nano"))
menu_name = "nano";
else
menu_name = "st";
} else {
hide_menu();
menu_mode = MODE_NONE;
snprintf(cmd, sizeof(cmd), "sxmo_appmenu.sh --fallback '%s' '%s'", cls, ttl);
spawn_detached_sh(cmd);
return;
/* launched from a terminal: also show the exact same Sys menu */
menu_name = "sys";
}
else {
/* launched from an app: show the exact same Sys menu as the desktop */
menu_name = "sys";
}
}