X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=sys-win32.c;h=cfaeedf70e614851ab8d25e73ee03fcfd045ca9f;hb=5dd54ab27b27c888741e5700aad89226009eb449;hp=8ec77ffe0da4f6072c818a658d664a964ea58b83;hpb=d7d862c402564b4fe29f17e1a55cdbb2967aa6fd;p=wmpus diff --git a/sys-win32.c b/sys-win32.c index 8ec77ff..cfaeedf 100644 --- a/sys-win32.c +++ b/sys-win32.c @@ -26,21 +26,6 @@ typedef struct { int vk; } keymap_t; -win_t *win_new(HWND hwnd) -{ - RECT rect = {}; - GetWindowRect(hwnd, &rect); - win_t *win = new0(win_t); - win->x = rect.left; - win->y = rect.top; - win->w = rect.right - rect.left; - win->h = rect.bottom - rect.top; - win->sys = new0(win_sys_t); - win->sys->hwnd = hwnd; - return win; -} - -/* Conversion functions */ keymap_t key2vk[] = { {key_mouse1 , VK_LBUTTON }, {key_mouse2 , VK_MBUTTON }, @@ -78,17 +63,36 @@ keymap_t key2vk[] = { {key_win , VK_RWIN }, }; -UINT key2w(Key_t key) +/* Helper functions */ +win_t *win_new(HWND hwnd) { - keymap_t *km = map_get(key2vk,key); - return km ? km->vk : toupper(key); + RECT rect = {}; + GetWindowRect(hwnd, &rect); + win_t *win = new0(win_t); + win->x = rect.left; + win->y = rect.top; + win->w = rect.right - rect.left; + win->h = rect.bottom - rect.top; + win->sys = new0(win_sys_t); + win->sys->hwnd = hwnd; + return win; } + +/* Conversion functions */ +/* - Keycodes */ Key_t w2key(UINT vk) { keymap_t *km = map_getr(key2vk,vk); return km ? km->key : vk; } +UINT key2w(Key_t key) +{ + keymap_t *km = map_get(key2vk,key); + return km ? km->vk : toupper(key); +} + +/* - Pointers */ ptr_t getptr(void) { POINT wptr; @@ -96,23 +100,14 @@ ptr_t getptr(void) return (ptr_t){-1, -1, wptr.x, wptr.y}; } -/* Functions */ -void sys_move(win_t *win, int x, int y, int w, int h) -{ - printf("sys_move: %p - %d,%d %dx%d\n", win, x, y, w, h); - MoveWindow(win->sys->hwnd, x, y, w, h, TRUE); -} - -void sys_raise(win_t *win) -{ - printf("sys_raise: %p\n", win); -} - -void sys_watch(win_t *win, Key_t key, mod_t mod) +win_t *getwin(void) { - printf("sys_watch: %p\n", win); + POINT wptr; + GetCursorPos(&wptr); + return win_new(GetAncestor(WindowFromPoint(wptr),GA_ROOT)); } +/* Callbacks */ LRESULT CALLBACK KbdProc(int msg, WPARAM wParam, LPARAM lParam) { KBDLLHOOKSTRUCT *st = (KBDLLHOOKSTRUCT *)lParam; @@ -126,15 +121,13 @@ LRESULT CALLBACK KbdProc(int msg, WPARAM wParam, LPARAM lParam) msg, wParam, lParam, st->vkCode, st->scanCode, st->flags, key, mod2int(mod_state)); - HWND fghwnd = GetForegroundWindow(); - wm_handle_key(win_new(fghwnd), key, mod_state, getptr()); + wm_handle_key(getwin(), key, mod_state, getptr()); return CallNextHookEx(0, msg, wParam, lParam); } LRESULT CALLBACK MllProc(int msg, WPARAM wParam, LPARAM lParam) { Key_t key = key_none; - HWND fghwnd = GetForegroundWindow(); switch (wParam) { case WM_LBUTTONDOWN: mod_state.up = 0; key = key_mouse1; break; case WM_LBUTTONUP: mod_state.up = 1; key = key_mouse1; break; @@ -142,9 +135,9 @@ LRESULT CALLBACK MllProc(int msg, WPARAM wParam, LPARAM lParam) case WM_RBUTTONUP: mod_state.up = 1; key = key_mouse3; break; } if (wParam == WM_MOUSEMOVE) - return wm_handle_ptr(win_new(fghwnd), getptr()); + return wm_handle_ptr(getwin(), getptr()); else if (key != key_none) - return wm_handle_key(win_new(fghwnd), key, mod_state, getptr()); + return wm_handle_key(getwin(), key, mod_state, getptr()); else return CallNextHookEx(0, msg, wParam, lParam); } @@ -182,6 +175,56 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hwnd, msg, wParam, lParam); } +/***************** + * Sys functions * + *****************/ +void sys_move(win_t *win, int x, int y, int w, int h) +{ + printf("sys_move: %p - %d,%d %dx%d\n", win, x, y, w, h); + MoveWindow(win->sys->hwnd, x, y, w, h, TRUE); +} + +void sys_raise(win_t *win) +{ + printf("sys_raise: %p\n", win); + SetForegroundWindow(win->sys->hwnd); + //HWND hwnd = win->sys->hwnd; + //HWND top = GetAncestor(hwnd,GA_ROOT); + //SetWindowPos(top, HWND_TOPMOST, 0, 0, 0, 0, + // SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); +} + +void sys_focus(win_t *win) +{ + printf("sys_focus: %p\n", win); + //POINT wptr; + //GetCursorPos(&wptr); + //HWND old = GetForegroundWindow(); + //HWND newc = WindowFromPoint(wptr); + //HWND new = GetAncestor(newc,GA_ROOT); + //SetWindowPos(new, HWND_NOTOPMOST, 0, 0, 0, 0, + // SWP_NOMOVE|SWP_NOSIZE); + //SetWindowPos(old, HWND_NOTOPMOST, 0, 0, 0, 0, + // SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + //SetFocus(hwnd); + //SetActiveWindow(hwnd); + + // Go to: HKEY_CURRENT_USER\Control Panel\Mouse + // Modify/Create DWORD Value of Data type REG_DWORD Named [ActiveWindowTracking] Setting for Value Data: [0 = ActiveWindowTracking Disabled / 1 = ActiveWindowTracking Enabled] + + //LockSetForegroundWindow(LSFW_LOCK); + //SetForegroundWindow(win->sys->hwnd); + //LockSetForegroundWindow(LSFW_UNLOCK); + //SetFocus(win->sys->hwnd); + //SetActiveWindow(win->sys->hwnd); + //EnableWindow(win->sys->hwnd, TRUE); +} + +void sys_watch(win_t *win, Key_t key, mod_t mod) +{ + printf("sys_watch: %p\n", win); +} + win_t *sys_init(void) { HINSTANCE hInst = GetModuleHandle(NULL);