Skip to content

Commit

Permalink
v1.01 wip
Browse files Browse the repository at this point in the history
chg: display zxdb version within about dialog
chg: bump up zxdb to latest
chg: move titlebar logic to a separate file

fix: alt-enter not going fullscreen on linux/osx (3rd_tigr)
fix: allow ini fields to be read in any order
fix: local browser setting was preventing ZXDB browser to show up in fresh restarts
  • Loading branch information
r-lyeh committed Jul 11, 2024
1 parent 4f67871 commit c41f247
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/3rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "3rd_tigrobjc.h"
#include "3rd_tigrmousecursor.h"
#include "3rd_tigrdragndrop.h"
#include "3rd_tigrtitle.h"
#undef border
#undef run

Expand Down
38 changes: 38 additions & 0 deletions src/3rd_tigr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4042,6 +4042,11 @@ void _tigrOnCocoaEvent(id event, id window) {
}
}

#if 1 // @r-lyeh
if( win->keys[TK_ALT] && win->keys[TK_RETURN] && !win->prev[TK_RETURN] )
objc_msgSend_void_id(window, sel("toggleFullScreen:"), window);
#endif

// Pass through cmd+key
if (win->keys[TK_LWIN]) {
break;
Expand Down Expand Up @@ -5283,6 +5288,32 @@ static void tigrInterpretChar(TigrInternal* win, Window root, unsigned int keyco
}
}

#if 1 // @r-lyeh
#ifndef _NET_WM_STATE_TOGGLE
#define _NET_WM_STATE_TOGGLE 2
#endif
static int tigrToggleFullscreen(TigrInternal* win)
{
XEvent xev;
long evmask = SubstructureRedirectMask | SubstructureNotifyMask;

xev.type = ClientMessage;
xev.xclient.window = win->win;
xev.xclient.message_type = XInternAtom(dpy, "_NET_WM_STATE", False); //_NET_WM_STATE;
xev.xclient.format = 32;
xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE; /* action */
xev.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); /* first property to toggle */
xev.xclient.data.l[2] = 0; /* no second property to toggle */
xev.xclient.data.l[3] = 1; /* source indication: application */
xev.xclient.data.l[4] = 0; /* unused */

if(!XSendEvent(win->dpy, DefaultRootWindow(win->dpy), 0, evmask, &xev)) {
return -1;
}
return 0;
}
#endif

static void tigrProcessInput(TigrInternal* win, int winWidth, int winHeight) {
{
Window focused;
Expand Down Expand Up @@ -5348,6 +5379,13 @@ static void tigrProcessInput(TigrInternal* win, int winWidth, int winHeight) {
}
memcpy(prevKeys, keys, 32);

#if 1 // @r-lyeh
if( win->keys[TK_LALT] || win->keys[TK_RALT] )
if( win->keys[TK_RETURN] && !win->prev[TK_RETURN] ) {
tigrToggleFullscreen(win);
}
#endif

XEvent event;
while (XCheckTypedWindowEvent(win->dpy, win->win, ClientMessage, &event)) {
if (event.xclient.data.l[0] == wmDeleteMessage) {
Expand Down
20 changes: 20 additions & 0 deletions src/3rd_tigrtitle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
char* tigrTitle(Tigr *win, const char *title) {
static char copy[128] = {0};
if( title ) {
#ifdef __APPLE__

#elif defined _WIN32
SetWindowTextA((HWND)(win->handle), title);
#else
XTextProperty prop;
int result = Xutf8TextListToTextProperty(dpy, (char**)&title, 1, XUTF8StringStyle, &prop);
if (result == Success) {
Atom wmName = XInternAtom(dpy, "_NET_WM_NAME", 0);
XSetTextProperty(tigrInternal(win)->dpy, tigrInternal(win)->win, &prop, wmName);
XFree(prop.value);
}
#endif
snprintf(copy, 128, "%s", title);
}
return copy;
}
16 changes: 12 additions & 4 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// glue sequential tzx/taps in zips (side A) -> side 1 etc)
// sequential tzx/taps/dsks do not reset model

#define SPECTRAL "v1.0"
#define SPECTRAL "v1.01 wip"

#define README \
"Spectral can be configured with a mouse.\n\n" \
Expand Down Expand Up @@ -58,6 +58,11 @@
// [ ] db interface (F2 to rename)
// on hover: show animated state if exists. show loading screen otherwise.
// [ ] embed torrent server/client to mirror the WOS/ZXDB/NVG/Archive.org distros
// http://www.kristenwidman.com/blog/33/how-to-write-a-bittorrent-client-part-1/
// https://wiki.theory.org/BitTorrentSpecification
// http://bittorrent.org/beps/bep_0003.html
// https://github.com/willemt/yabtorrent
// https://github.com/jech/dht
//
// idea: when stop-block is off
// - turn autoplay=off
Expand Down Expand Up @@ -167,7 +172,9 @@ int screenshot(const char *filename) {
int load_config() {
int errors = 0;
if( !ZX_PLAYER ) for( FILE *fp = fopen(".Spectral/Spectral.ini", "rt"); fp; fclose(fp), fp = 0 ) {
#define INI_LOAD(opt) errors += fscanf(fp, "%*[^=]=%d\n", &opt) > 1;
int tmp; char buf[128]; errors += fscanf(fp, "%s=%d", buf, &tmp) > 1;
#define INI_LOAD(opt) else if( strcmpi(buf, #opt) == 0 ) opt = tmp;
if(0);
INI_OPTIONS(INI_LOAD)
}
return !errors;
Expand Down Expand Up @@ -255,8 +262,9 @@ void help() {
char *help = va(
"Spectral " SPECTRAL " (Public Domain).\n"
"https://github.com/r-lyeh/Spectral\n\n"
"Library: %d games found (%d%%)\n\n"
README "\n", numgames, 100 - (numerr * 100 / (total + !total)));
"ZXDB %s: %d entries\n"
"Local Library: %d games found (%d%%)\n\n"
README "\n", ZXDB_VERSION, zxdb_count(), numgames, 100 - (numerr * 100 / (total + !total)));
(alert)("Spectral " SPECTRAL, help);
}

Expand Down
Binary file modified src/res/zxdb/Spectral.db.gz
Binary file not shown.
1 change: 1 addition & 0 deletions src/res/zxdb/ZXDB_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define ZXDB_VERSION "Version 1.0.197"
3 changes: 2 additions & 1 deletion src/res/zxdb/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
rem checks. compile if needed
where /q python.exe || (echo cannot find python.exe in path && exit /b)
where /q sqlite3.exe || (cl sqlite3.c shell.c /MT || exit /b)
where /q zxdb2txt.exe || (cl zxdb2txt.c sqlite3.c /MT /Ox /Oy || exit /b)
where /q zxdb2txt.exe || (cl zxdb2txt.c sqlite3.c -DDEV=0 /MT /Ox /Oy || exit /b)
if exist *.obj del *.obj
if exist Z*.sql* del Z*.sql*

rem clone
rd /q /s ZXDB >nul 2>nul
git clone --depth 1 https://github.com/ZXDB/ZXDB && ^
pushd ZXDB && (git log --oneline --pretty="#define ZXDB_VERSION \"%%s\"" ZXDB_mysql.sql.zip > ..\ZXDB_version.h) && popd && ^
python -m zipfile -e ZXDB\ZXDB_mysql.sql.zip . && ^
python ZXDB\scripts\ZXDB_to_SQLite.py && ^
rd /q /s ZXDB >nul 2>nul
Expand Down
25 changes: 1 addition & 24 deletions src/sys_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define window_pressed(win, keycode) (!!(tigrKeyDown(win, keycode) || tigrKeyHeld(win, keycode)))
#define window_trigger(win, keycode) (!!tigrKeyDown(win, keycode))
void window_override_icons();
char* window_title(window *win, const char *title);
#define window_title(win, title) tigrTitle(win,title)


int window_keyrepeat(window *app, unsigned char vk) {
Expand Down Expand Up @@ -82,28 +82,6 @@ char* prompt(const char *title, const char *body, const char *defaults ) {

#endif


char* window_title(window *win, const char *title) {
static char copy[128] = {0};
if( title ) {
#ifdef __APPLE__

#elif defined _WIN32
SetWindowTextA((HWND)(((Tigr*)win)->handle), title);
#else
XTextProperty prop;
int result = Xutf8TextListToTextProperty(dpy, (char**)&title, 1, XUTF8StringStyle, &prop);
if (result == Success) {
Atom wmName = XInternAtom(dpy, "_NET_WM_NAME", 0);
XSetTextProperty(tigrInternal(win)->dpy, tigrInternal(win)->win, &prop, wmName);
XFree(prop.value);
}
#endif
snprintf(copy, 128, "%s", title);
}
return copy;
}

int (alert)(const char *title, const char *body) {
#ifdef _WIN32
MessageBoxA(0, body, title, MB_OK);
Expand All @@ -126,4 +104,3 @@ void die(const char *msg) {
#endif
exit(-1);
}

2 changes: 1 addition & 1 deletion src/zx.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int ZX_ALTROMS = 0; // 0:(no, original), 1:(yes, custom)
X(ZX_FPS) \
X(ZX_AUTOLOCALE) \
X(ZX_FASTTAPE) \
X(ZX_BROWSER) \
/*X(ZX_BROWSER)*/ \
X(ZX_ALTROMS)

void logport(word port, byte value, int is_out);
Expand Down
3 changes: 3 additions & 0 deletions src/zx_db.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// header

#include "res/zxdb/ZXDB_version.h"

typedef struct zxdb {
char *copy, *tok;
char *ids[9]; // "#id|year|title|alias|publisher|type|score|genre|#tags"
Expand Down Expand Up @@ -468,6 +470,7 @@ char* zxdb_download_(const char *url, int *len) {
}
else if( !strncmp(url, "/pub/", 5) ) {
// ok, redirection
// mirror = "https://worldofspectrum.net/";
mirror = "https://archive.org/download/World_of_Spectrum_June_2017_Mirror/World%20of%20Spectrum%20June%202017%20Mirror.zip/World%20of%20Spectrum%20June%202017%20Mirror/";
url += 5;
}
Expand Down

0 comments on commit c41f247

Please sign in to comment.