From c456ae707f58f8dfca235f5c6939267efdfe24b9 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 04 2024 04:17:15 +0000 Subject: use strut to make dock --- diff --git a/app.c b/app.c index 62511be..77f1103 100644 --- a/app.c +++ b/app.c @@ -69,8 +69,8 @@ int appInit(App *app) { | ButtonReleaseMask | Button1MotionMask ); - LOGDBG("app: init: set window title"); #ifndef NOBORDER + LOGDBG("app: init: set window title"); char *title = TITLE; XTextProperty wtitle; if (!XStringListToTextProperty(&title, 1, &wtitle)) { @@ -79,19 +79,23 @@ int appInit(App *app) { XSetWMName(app->dpy, app->win, &wtitle); XFree(wtitle.value); } - #ifdef DOCK - Atom wt = XInternAtom(app->dpy, "_NET_WM_WINDOW_TYPE", False); - //Atom wtval = XInternAtom(app->dpy, "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE", False); - Atom wtval = XInternAtom(app->dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False); - if (wt != None && wtval != None) - XChangeProperty(app->dpy, app->win, wt, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wtval, 1); - Atom pm = XInternAtom(app->dpy, "_HILDON_PORTRAIT_MODE_SUPPORT", False); - unsigned int pmval = 1; - if (pm) - XChangeProperty(app->dpy, app->win, pm, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&pmval, 1); #endif + + #if !defined(NOBORDER) && defined(DOCK) + LOGDBG("app: init: set window as dock"); + Atom awt = XInternAtom(app->dpy, "_NET_WM_WINDOW_TYPE", False); + Atom awtv = XInternAtom(app->dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False); + if (awt != None && awtv != None) + XChangeProperty(app->dpy, app->win, awt, XA_ATOM, 32, PropModeReplace, (unsigned char*)&awtv, 1); #endif + Atom ahps = XInternAtom(app->dpy, "_HILDON_PORTRAIT_MODE_SUPPORT", False); + if (ahps) { + LOGDBG("app: init: set portrait mode support for hildon"); + unsigned int v = 1; + XChangeProperty(app->dpy, app->win, ahps, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&v, 1); + } + LOGDBG("app: init: set window minimum size"); XSizeHints *wsh = XAllocSizeHints(); if (!wsh) { @@ -175,6 +179,7 @@ int appRun(App *app) { LOGDBG("app: run: show window"); XMapWindow(app->dpy, app->win); + appUpdateStrut(app); LOGDBG("app: run: get connection file descriptor"); int fd = ConnectionNumber(app->dpy); @@ -247,6 +252,7 @@ int appRun(App *app) { app->y = event.xconfigure.y; app->w = event.xconfigure.width; app->h = event.xconfigure.height; + appUpdateStrut(app); if (resized) graphResize(&app->graph); } break; @@ -347,8 +353,30 @@ void appStop(App *app, int err) { } +void appUpdateStrut(App *app) { + unsigned int v[4] = {}; + + #ifdef DOCK + if (app->y == 0) v[2] = app->h; else + if (app->y + app->h == app->sh) v[3] = app->h; + #endif + + if (app->dockt == v[2] && app->dockb == v[3]) + return; + app->dockt = v[2]; + app->dockb = v[3]; + + Atom k = XInternAtom(app->dpy, "_NET_WM_STRUT", False); + if (!k) return; + + LOGDBG("app: update strut: %u %u %u %u", v[0], v[1], v[2], v[3]); + XChangeProperty(app->dpy, app->win, k, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)v, 4); +} + + void appUpdateScreenSize(App *app, int sw, int sh) { if (sw <= 0 || sh <= 0) return; + if (sw == app->sw && sh == app->sh) return; LOGDBG("app: update screen size: w=%d, h=%d", sw, sh); diff --git a/app.h b/app.h index bf5345a..56d3e0f 100644 --- a/app.h +++ b/app.h @@ -26,6 +26,7 @@ struct App { int run; int sw, sh; int x, y, w, h; + int dockt, dockb; int irx, iry, irw, irh; int xron, xrev, xrerr; }; @@ -35,6 +36,7 @@ int appInit(App *app); void appDeinit(App *app); int appRun(App *app); void appStop(App *app, int err); +void appUpdateStrut(App *app); void appUpdateScreenSize(App *app, int sw, int sh); void appMove(App *app, int x, int y, int w, int h); void appInvalidateRect(App *app, int x, int y, int w, int h);