From bf75f4b91ab378e436cfa8cc9eab1f0e9720a4b6 Mon Sep 17 00:00:00 2001 From: Kylogias <45217130+Kylogias@users.noreply.github.com> Date: Tue, 7 May 2024 21:58:17 -0400 Subject: [PATCH] Window Focus Support --- CNFG.h | 1 + CNFGWinDriver.c | 5 +++++ CNFGXDriver.c | 7 ++++++- rawdraw_sf.h | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CNFG.h b/CNFG.h index 920087b..36d7ead 100644 --- a/CNFG.h +++ b/CNFG.h @@ -204,6 +204,7 @@ extern float CNFGVertDataV[CNFG_BATCH*3]; extern uint32_t CNFGVertDataC[CNFG_BATCH]; #endif +#define CNFG_KEY_FOCUS 0xf000 #if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) diff --git a/CNFGWinDriver.c b/CNFGWinDriver.c index a8ce10a..c01ddea 100644 --- a/CNFGWinDriver.c +++ b/CNFGWinDriver.c @@ -179,6 +179,11 @@ LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; #endif + case WM_KILLFOCUS: + case WM_SETFOCUS: + CNFGLastScancode = 0; + HandleKey( CNFG_KEY_FOCUS, msg == WM_SETFOCUS ); + return 0; case WM_CLOSE: if( HandleDestroy() ) return 0; diff --git a/CNFGXDriver.c b/CNFGXDriver.c index adfb4db..8e42f4c 100644 --- a/CNFGXDriver.c +++ b/CNFGXDriver.c @@ -223,7 +223,7 @@ static void InternalLinkScreenAndGo( const char * WindowName ) fprintf( stderr, "Pre-existing XClassHint\n" ); } - XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask ); + XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask | FocusChangeMask ); CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0); @@ -500,6 +500,11 @@ int CNFGHandleInput() case MotionNotify: HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 ); break; + case FocusIn: + case FocusOut: + CNFGLastScancode = 0; + HandleKey( CNFG_KEY_FOCUS, report.type == FocusIn ); + break; case ClientMessage: if ( report.xclient.data.l[0] == CFNGWMDeleteWindow ) return 0; diff --git a/rawdraw_sf.h b/rawdraw_sf.h index d690508..42c1eed 100644 --- a/rawdraw_sf.h +++ b/rawdraw_sf.h @@ -1,5 +1,5 @@ //This file was automatically generated by Makefile at https://github.com/cntools/rawdraw -//Generated from files git hash a4e1d56080c42e7d5a7d72317776c7c268764bd7 on Tue May 7 08:10:18 PM EDT 2024 (This is not the git hash of this file) +//Generated from files git hash c55fd6fe2c807fbe9103c7fb72dc277ebd641397 on Tue May 7 09:58:03 PM EDT 2024 (This is not the git hash of this file) // Copyright 2010-2021 <>< CNLohr, et. al. (Several other authors, many but not all mentioned) // Licensed under the MIT/x11 or NewBSD License you choose. // @@ -206,6 +206,7 @@ extern float CNFGVertDataV[CNFG_BATCH*3]; extern uint32_t CNFGVertDataC[CNFG_BATCH]; #endif +#define CNFG_KEY_FOCUS 0xf000 #if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) @@ -3892,6 +3893,11 @@ LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; #endif + case WM_KILLFOCUS: + case WM_SETFOCUS: + CNFGLastScancode = 0; + HandleKey( CNFG_KEY_FOCUS, msg == WM_SETFOCUS ); + break; case WM_CLOSE: if( HandleDestroy() ) return 0; @@ -5811,7 +5817,7 @@ static void InternalLinkScreenAndGo( const char * WindowName ) fprintf( stderr, "Pre-existing XClassHint\n" ); } - XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask ); + XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask | FocusChangeMask ); CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0); @@ -6088,6 +6094,11 @@ int CNFGHandleInput() case MotionNotify: HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 ); break; + case FocusIn: + case FocusOut: + CNFGLastScancode = 0; + HandleKey( CNFG_KEY_FOCUS, report.type == FocusIn ); + break; case ClientMessage: if ( report.xclient.data.l[0] == CFNGWMDeleteWindow ) return 0;