diff --git a/app.c b/app.c index fbec35c..ca1fa79 100644 --- a/app.c +++ b/app.c @@ -1,6 +1,8 @@ #include "app.h" +#include + #include #include #include @@ -34,6 +36,14 @@ int appInit(App *app) { app->x = 0; app->w = app->sw * WIDTH_SCALE; app->h = app->sh * HEIGHT_SCALE; + + #if defined(WIDTH_SCALE_P) && defined(HEIGHT_SCALE_P) + if (app->sw < app->sh) { + app->w = app->sw * WIDTH_SCALE; + app->h = app->sh * HEIGHT_SCALE; + } + #endif + #ifdef TOP app->y = 0; #else @@ -341,11 +351,30 @@ 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); - int hw = app->sw/2, hh = app->sh/2; - int x0 = (app->x*sw + hw)/app->sw; - int y0 = (app->y*sh + hh)/app->sh; - int x1 = ((app->x + app->w)*sw + hw)/app->sw; - int y1 = ((app->y + app->h)*sh + hh)/app->sh; + + double kx = sw/(double)app->sw; + double ky = sh/(double)app->sh; + + #if defined(WIDTH_SCALE_P) && defined(HEIGHT_SCALE_P) + // rescale for portrait/landscape switching + if (app->sw < app->sh && sw >= sh) { + // portrait -> landscape + kx *= ((double)WIDTH_SCALE)/((double)WIDTH_SCALE_P); + ky *= ((double)HEIGHT_SCALE)/((double)HEIGHT_SCALE_P); + } else + if (app->sw >= app->sh && sw < sh) { + // landscape -> portrait + kx *= ((double)WIDTH_SCALE_P)/((double)WIDTH_SCALE); + ky *= ((double)HEIGHT_SCALE_P)/((double)HEIGHT_SCALE); + } + #endif + + // scale window corners + int x0 = (int)round( app->x*kx ); + int y0 = (int)round( app->y*ky ); + int x1 = (int)round( (app->x + app->w)*kx ); + int y1 = (int)round( (app->y + app->h)*ky ); + app->sw = sw; app->sh = sh; appMove(app, x0, y0, x1 - x0, y1 - y0); diff --git a/build.sh b/build.sh index cfe21e4..4035ff9 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ set -e TARGET="coolkbd" FLAGS="$(pkg-config --cflags --libs x11 xft xtst xrandr)" -FLAGS="$FLAGS -Wall" +FLAGS="$FLAGS -Wall -lm" MODE_FLAGS="-O3 -DNDEBUG" diff --git a/config.h.example b/config.h.example index c6319cb..5e4bb9e 100644 --- a/config.h.example +++ b/config.h.example @@ -9,10 +9,13 @@ //#define DOCK //#define TOP_RESIZE //#define TOP -//#define SCREEN_EVENTS +#define SCREEN_EVENTS #define WIDTH_SCALE 1/1 // (nominator)/(denomitator) -#define HEIGHT_SCALE 1/3 +#define HEIGHT_SCALE 2/5 +//#define WIDTH_SCALE_P 1/1 // scales for portrait mode, if you need different +//#define HEIGHT_SCALE_P 1/3 // you need to comment/uncomment both lines + #define TITLE "coolkbd" #define MIN_WIDTH 200 diff --git a/maemo/config.h.bottom b/maemo/config.h.bottom index b86ad6a..8da8fa1 100644 --- a/maemo/config.h.bottom +++ b/maemo/config.h.bottom @@ -12,7 +12,9 @@ #define SCREEN_EVENTS #define WIDTH_SCALE 1/1 // (nominator)/(denomitator) -#define HEIGHT_SCALE 1/3 +#define HEIGHT_SCALE 2/5 +#define WIDTH_SCALE_P 1/1 // scales for portrait mode, if you need different +#define HEIGHT_SCALE_P 1/3 // you need to comment/uncomment both lines #define TITLE "coolkbd" #define MIN_WIDTH 200 diff --git a/maemo/config.h.dock b/maemo/config.h.dock index 7412d92..679aa8a 100644 --- a/maemo/config.h.dock +++ b/maemo/config.h.dock @@ -12,7 +12,9 @@ #define SCREEN_EVENTS #define WIDTH_SCALE 1/1 // (nominator)/(denomitator) -#define HEIGHT_SCALE 1/3 +#define HEIGHT_SCALE 2/5 +#define WIDTH_SCALE_P 1/1 // scales for portrait mode, if you need different +#define HEIGHT_SCALE_P 1/3 // you need to comment/uncomment both lines #define TITLE "coolkbd" #define MIN_WIDTH 200 diff --git a/maemo/config.h.top b/maemo/config.h.top index e8534aa..1fba283 100644 --- a/maemo/config.h.top +++ b/maemo/config.h.top @@ -12,7 +12,9 @@ #define SCREEN_EVENTS #define WIDTH_SCALE 1/1 // (nominator)/(denomitator) -#define HEIGHT_SCALE 1/3 +#define HEIGHT_SCALE 2/5 +#define WIDTH_SCALE_P 1/1 // scales for portrait mode, if you need different +#define HEIGHT_SCALE_P 1/3 // you need to comment/uncomment both lines #define TITLE "coolkbd" #define MIN_WIDTH 200