commit eef0f02de6e41a7a84c1075227ab50190db71e4a
parent 79c34965dfc787ffa791c2280518ef1efd13ed7a
Author: theSoberSobber <akshatshrivastava0010@gmail.com>
Date: Sun, 3 Dec 2023 18:43:07 +0530
parent 79c34965dfc787ffa791c2280518ef1efd13ed7a
Author: theSoberSobber <akshatshrivastava0010@gmail.com>
Date: Sun, 3 Dec 2023 18:43:07 +0530
VD Features
11 files changed, 113 insertions(+), 33 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ +/.vscode a.exe main.o sxhkd-win32.exe
diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -DEBUG = +DEBUG = -DDEBUG CFLAGS = -w -Wall -Os ${DEBUG} LDFLAGS = -s -mwindows CC = gcc
diff --git a/README.md b/README.md @@ -33,4 +33,4 @@ static Key keys[] = { # TODO - Installer (or start menu + program files) -- Scheduler +- Scheduler+ \ No newline at end of file
diff --git a/VD-action.md b/VD-action.md @@ -1,5 +1,9 @@ # VD-Action -- https://stackoverflow.com/a/55542867 -- https://github.com/Ciantic/VirtualDesktopAccessor/blob/master/VirtualDesktopAccessor/dllmain.h#L40 -- https://www.codeproject.com/Articles/13601/COM-in-plain-C -- https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cocreateinstance +- Native + - https://stackoverflow.com/a/55542867 + - https://github.com/Ciantic/VirtualDesktopAccessor/blob/master/VirtualDesktopAccessor/dllmain.h#L40 + - https://www.codeproject.com/Articles/13601/COM-in-plain-C + - https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cocreateinstance + +- [DLL Based](https://github.com/Ciantic/VirtualDesktopAccessor) + - Current Implementation+ \ No newline at end of file
diff --git a/VD/VD.c b/VD/VD.c @@ -0,0 +1,10 @@ +void MoveWindowToDesktopNumberW(const Arg* arg){ + printf("%d", arg->i - 1); + HWND fgwhwnd = (HWND)GetForegroundWindow(); + if(GetCurrentDesktopFunc()==GetWindowDesktopNumberFunc(fgwhwnd)) MoveWindowToDesktopNumberFunc(fgwhwnd, arg->i - 1); + SetForegroundWindow(NULL); +} + +void GoToDesktopNumberW(const Arg* arg){ + GoToDesktopNumberFunc((arg->i - 1 + 10)%10); +}+ \ No newline at end of file
diff --git a/VD/VD.h b/VD/VD.h @@ -0,0 +1,2 @@ +static void GoToDesktopNumberW(const Arg* arg); +static void MoveWindowToDesktopNumberW(const Arg* arg);+ \ No newline at end of file
diff --git a/VirtualDesktopAccessor.dll b/VirtualDesktopAccessor.dll Binary files differ.
diff --git a/actions.c b/actions.c @@ -0,0 +1,27 @@ +/* Actions Implementation */ + +void quit(const Arg* arg) { + PostMessage(dwmhwnd, WM_CLOSE, 0, 0); +} + +void test(const Arg* arg) { + dbg("Hello from handler!\n"); +} + +void spawn(const Arg *arg) { + ShellExecute(NULL, NULL, ((char **)arg->v)[0], ((char **)arg->v)[1], NULL, SW_SHOWDEFAULT); +} + +void toggleexplorer(const Arg *arg) { +#define setvisibility(x, y) SetWindowPos(x, 0, 0, 0, 0, 0, (y ? SWP_SHOWWINDOW : SWP_HIDEWINDOW) | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); + HWND hwnd = FindWindow("Progman", "Program Manager"); + if (hwnd) setvisibility(hwnd, !IsWindowVisible(hwnd)); + + hwnd = FindWindow("Shell_TrayWnd", NULL); + if (hwnd) setvisibility(hwnd, !IsWindowVisible(hwnd)); +} +#ifdef VDA_FEATURES +#include "VD/VD.c" +#endif + +/* Actions End here */+ \ No newline at end of file
diff --git a/actions.h b/actions.h @@ -1,4 +1,10 @@ +#define VDA_FEATURES + static void test(const Arg* arg); static void quit(const Arg* arg); static void spawn(const Arg* arg); -static void toggleexplorer(const Arg* arg);- \ No newline at end of file +static void toggleexplorer(const Arg* arg); + +#ifdef VDA_FEATURES +#include "VD/VD.h" +#endif+ \ No newline at end of file
diff --git a/config.h b/config.h @@ -4,16 +4,33 @@ // Use MODKEY | MOD_SHIFT for mod + shift // VK_RETURN == RETURN KEY on Keyboard +// VK_TAB == TAB KEY on Keyboard // command, argument static const char *termcmd[] = { "wt.exe", NULL }; static const char *vscode[] = {"code", "D:/code"}; +#define NUMKEY(x) \ + {MODKEY, x+'0', GoToDesktopNumberW, {.i= x ? x : 10}}, \ + {MODKEY|MOD_SHIFT, x+'0', MoveWindowToDesktopNumberW, {.i= x ? x : 10}} + static Key keys[] = { /* modifier key function argument */ { MODKEY, 'B', test, {0} }, { MODKEY, 'P', spawn, {.v = vscode} }, { MODKEY, VK_RETURN, spawn, {.v = termcmd } }, { MODKEY, 'E', toggleexplorer, {0} }, - { MODKEY | MOD_SHIFT, 'Q', quit, {0} } + { MODKEY | MOD_SHIFT, 'Q', quit, {0} }, + #ifdef VDA_FEATURES + NUMKEY(1), + NUMKEY(2), + NUMKEY(3), + NUMKEY(4), + NUMKEY(5), + NUMKEY(6), + NUMKEY(7), + NUMKEY(8), + NUMKEY(9), + NUMKEY(0), + #endif };
diff --git a/main.c b/main.c @@ -28,34 +28,28 @@ typedef struct { HWND dwmhwnd; -/* Actions Implementation */ - -void quit(const Arg* arg) { - PostMessage(dwmhwnd, WM_CLOSE, 0, 0); -} - -void test(const Arg* arg) { - dbg("Hello from handler!\n"); -} - -void spawn(const Arg *arg) { - ShellExecute(NULL, NULL, ((char **)arg->v)[0], ((char **)arg->v)[1], NULL, SW_SHOWDEFAULT); -} - -void toggleexplorer(const Arg *arg) { -#define setvisibility(x, y) SetWindowPos(x, 0, 0, 0, 0, 0, (y ? SWP_SHOWWINDOW : SWP_HIDEWINDOW) | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); - HWND hwnd = FindWindow("Progman", "Program Manager"); - if (hwnd) setvisibility(hwnd, !IsWindowVisible(hwnd)); - - hwnd = FindWindow("Shell_TrayWnd", NULL); - if (hwnd) setvisibility(hwnd, !IsWindowVisible(hwnd)); -} +#ifdef VDA_FEATURES +HMODULE VDA; + +typedef int(*GoToDesktopNumber)(int); +typedef int(*MoveWindowToDesktopNumber)(HWND, int); +typedef int(*GetCurrentDesktop)(); +typedef int(*GetWindowDesktopNumber)(HWND); + +GetCurrentDesktop GetCurrentDesktopFunc; +MoveWindowToDesktopNumber MoveWindowToDesktopNumberFunc; +GoToDesktopNumber GoToDesktopNumberFunc; +GetWindowDesktopNumber GetWindowDesktopNumberFunc; +#endif -/* Actions End here */ +#include "actions.c" void cleanup() { for (int i = 0; i < LENGTH(keys); i++) UnregisterHotKey(dwmhwnd, i + 1); DestroyWindow(dwmhwnd); + #ifdef VDA_FEATURES + FreeLibrary(VDA); + #endif } void die(const char *errstr, ...) { @@ -126,7 +120,21 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine #endif dbg("Hello!! : ))\n"); - + #ifdef VDA_FEATURES + char* libName = "\\VirtualDesktopAccessor.dll"; + TCHAR libFullPath[MAX_PATH + 1] = { 0 }; + GetCurrentDirectory(MAX_PATH, libFullPath); + // for(int i=0; libFullPath[i]; i++) if(libFullPath[i]=='\\') libFullPath[i]='/'; + strcat_s(libFullPath, sizeof libFullPath, libName); + VDA = LoadLibrary(libFullPath); + if (VDA == NULL){ + printf("Failed to load the DLL, VD Features will not work"); + }; + MoveWindowToDesktopNumberFunc = (MoveWindowToDesktopNumber)GetProcAddress(VDA, "MoveWindowToDesktopNumber"); + GoToDesktopNumberFunc = (GoToDesktopNumber)GetProcAddress(VDA, "GoToDesktopNumber"); + GetCurrentDesktopFunc = (GetCurrentDesktop)GetProcAddress(VDA, "GetCurrentDesktopNumber"); + GetWindowDesktopNumberFunc = (GetWindowDesktopNumber)GetProcAddress(VDA, "GetWindowDesktopNumber"); + #endif MSG msg; setup(hInstance);
: nply/dwhkd