diff --git a/keyswap_service.sh b/keyswap_service.sh index c389788..cdf8412 100755 --- a/keyswap_service.sh +++ b/keyswap_service.sh @@ -4,7 +4,6 @@ swapcmd="\/bin\/bash\ \/home\/`whoami`\/.config\/kinto\/xactive.sh" mkdir -p ~/.config/systemd/user mkdir -p ~/.config/autostart cp ./system-config/keyswap.service ~/.config/systemd/user/keyswap.service -cp ./system-config/keyswap.sh ~/.config/autostart/keyswap.sh cp ./kintox11/binary/kintox11 ~/.config/kinto/kintox11 cp ./system-config/xactive.sh ~/.config/kinto/xactive.sh sed -i "s/{username}/`whoami`/g" ~/.config/systemd/user/keyswap.service diff --git a/kintox11/binary/kintox11 b/kintox11/binary/kintox11 index bd2c6c8..a91a999 100755 Binary files a/kintox11/binary/kintox11 and b/kintox11/binary/kintox11 differ diff --git a/kintox11/src/kintox11.c b/kintox11/src/kintox11.c index b002a63..eea1559 100644 --- a/kintox11/src/kintox11.c +++ b/kintox11/src/kintox11.c @@ -88,6 +88,39 @@ Window get_focus_window(Display* d){ return w; } +// get the top window. +// a top window have the following specifications. +// * the start window is contained the descendent windows. +// * the parent window is the root window. +Window get_top_window(Display* d, Window start){ + Window w = start; + Window parent = start; + Window root = None; + Window *children; + unsigned int nchildren; + Status s; + + printf("getting top window ... \n"); + while (parent != root) { + w = parent; + s = XQueryTree(d, w, &root, &parent, &children, &nchildren); // see man + + if (s) + XFree(children); + + if(xerror){ + printf("fail\n"); + exit(1); + } + + printf(" get parent (window: %d)\n", (int)w); + } + + printf("success (window: %d)\n", (int)w); + + return w; +} + const char * str_window_class(Display* d, Window w, char *prior_app ){ Status s; @@ -243,6 +276,7 @@ int main(void){ Display* d; Window w; + char *name; // for XmbTextPropertyToTextList setlocale(LC_ALL, ""); // see man locale @@ -259,12 +293,19 @@ int main(void){ // get active window w = get_focus_window(d); + w = get_top_window(d, w); + + // XFetchName(d, w, &name); + // printf("window:%#x name:%s\n", w, name); + printf("First window name: %s \n",str_window_class(d, w,prior_app)); int breakouter; for (;;) { breakouter = 0; + // XFetchName(d, w, &name); + // printf("window:%#x name:%s\n", w, name); // printf("%s\n","1"); // printf("%s\n",str_window_class(d, w,prior_app)); if(strcmp(str_window_class(d, w,prior_app),prior_app)){ diff --git a/system-config/keyswap.service b/system-config/keyswap.service index b7e3bd6..a39428f 100755 --- a/system-config/keyswap.service +++ b/system-config/keyswap.service @@ -8,6 +8,7 @@ Type=simple #Group={username} Environment=DISPLAY=:0 Restart=always +RestartSec=5 WorkingDirectory=/home/{username}/.config/kinto ExecStart= diff --git a/system-config/keyswap.sh b/system-config/keyswap.sh deleted file mode 100755 index 2c81a04..0000000 --- a/system-config/keyswap.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/bash - -systemctl --user start keyswap \ No newline at end of file