games: auto-size windows to available screen; dmenu shows Sys menu from any app
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10
-5
@@ -22,8 +22,7 @@
|
|||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
static const int WIN_W = 220;
|
static const int TOPBAR = 24;
|
||||||
static const int WIN_H = 268;
|
|
||||||
static const int COLS = 24;
|
static const int COLS = 24;
|
||||||
static const int ROWS = 28;
|
static const int ROWS = 28;
|
||||||
|
|
||||||
@@ -86,8 +85,8 @@ static Window win;
|
|||||||
static GC gc;
|
static GC gc;
|
||||||
static Pixmap back;
|
static Pixmap back;
|
||||||
static int screen;
|
static int screen;
|
||||||
static int winW = WIN_W, winH = WIN_H;
|
|
||||||
static int cell, gx0, gy0, gw, gh;
|
static int cell, gx0, gy0, gw, gh;
|
||||||
|
static int winW = 240, winH = 296; // overridden at runtime from the actual screen
|
||||||
|
|
||||||
// ---- colors (Nokia green monochrome) ----
|
// ---- colors (Nokia green monochrome) ----
|
||||||
static unsigned long C_BG, C_FG, C_HEAD, C_FOOD, C_DIM;
|
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);
|
XFillRectangle(dpy, back, gc, 0, 0, winW, winH);
|
||||||
|
|
||||||
// playfield border (single clean frame around the grid)
|
// playfield border (single clean frame around the grid)
|
||||||
|
// border framing the whole window (adapts to the actual screen size)
|
||||||
XSetForeground(dpy, gc, C_DIM);
|
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
|
// food
|
||||||
if (foodx >= 0) {
|
if (foodx >= 0) {
|
||||||
XSetForeground(dpy, gc, C_FOOD);
|
XSetForeground(dpy, gc, C_FOOD);
|
||||||
@@ -286,6 +285,12 @@ static void setup_window() {
|
|||||||
dpy = XOpenDisplay(nullptr);
|
dpy = XOpenDisplay(nullptr);
|
||||||
if (!dpy) { fprintf(stderr, "snake: cannot open display\n"); exit(1); }
|
if (!dpy) { fprintf(stderr, "snake: cannot open display\n"); exit(1); }
|
||||||
screen = DefaultScreen(dpy);
|
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,
|
win = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, winW, winH, 0,
|
||||||
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
|
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
|
||||||
XStoreName(dpy, win, "Snake");
|
XStoreName(dpy, win, "Snake");
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
static const int WIN_W = 224;
|
static const int TOPBAR = 24;
|
||||||
static const int WIN_H = 292;
|
|
||||||
static const int PCOLS = 10;
|
static const int PCOLS = 10;
|
||||||
static const int PROWS = 20;
|
static const int PROWS = 20;
|
||||||
static const int CELL = 14;
|
static const int CELL = 14;
|
||||||
@@ -87,7 +86,7 @@ static Window win;
|
|||||||
static GC gc;
|
static GC gc;
|
||||||
static Pixmap back;
|
static Pixmap back;
|
||||||
static int screen;
|
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;
|
static unsigned long C_BG, C_FG, C_HEAD, C_FOOD, C_DIM;
|
||||||
|
|
||||||
// ---- tetromino definitions (state 0 within a 4x4 box) ----
|
// ---- tetromino definitions (state 0 within a 4x4 box) ----
|
||||||
@@ -328,6 +327,12 @@ static void setup_window() {
|
|||||||
dpy = XOpenDisplay(nullptr);
|
dpy = XOpenDisplay(nullptr);
|
||||||
if (!dpy) { fprintf(stderr, "tetris: cannot open display\n"); exit(1); }
|
if (!dpy) { fprintf(stderr, "tetris: cannot open display\n"); exit(1); }
|
||||||
screen = DefaultScreen(dpy);
|
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,
|
win = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, winW, winH, 0,
|
||||||
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
|
CopyFromParent, InputOutput, CopyFromParent, 0, nullptr);
|
||||||
XStoreName(dpy, win, "Tetris");
|
XStoreName(dpy, win, "Tetris");
|
||||||
|
|||||||
+6
-10
@@ -1649,16 +1649,12 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
|||||||
if (!cls[0] || strcmp(cls, "sys") == 0) {
|
if (!cls[0] || strcmp(cls, "sys") == 0) {
|
||||||
menu_name = "sys";
|
menu_name = "sys";
|
||||||
} else if (strcmp(cls, "st") == 0 || strncmp(cls, "st-", 3) == 0) {
|
} else if (strcmp(cls, "st") == 0 || strncmp(cls, "st-", 3) == 0) {
|
||||||
if (strstr(ttl, "nano"))
|
/* launched from a terminal: also show the exact same Sys menu */
|
||||||
menu_name = "nano";
|
menu_name = "sys";
|
||||||
else
|
}
|
||||||
menu_name = "st";
|
else {
|
||||||
} else {
|
/* launched from an app: show the exact same Sys menu as the desktop */
|
||||||
hide_menu();
|
menu_name = "sys";
|
||||||
menu_mode = MODE_NONE;
|
|
||||||
snprintf(cmd, sizeof(cmd), "sxmo_appmenu.sh --fallback '%s' '%s'", cls, ttl);
|
|
||||||
spawn_detached_sh(cmd);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user