diff options
| author | Joel Klinghed <the_jk@opera.com> | 2020-03-31 12:01:27 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@opera.com> | 2020-03-31 12:01:27 +0200 |
| commit | 5c0636e1645856849787abfbcfb7a1d9fe3f9f34 (patch) | |
| tree | ccf3c9b81b43fcbae8699f5fe5833fef6c1de1c8 | |
| parent | ccda9166c254581c95d5c84f0bb8136bba247ddd (diff) | |
Add support for -prefix to see how the desktop number was calculated
| -rw-r--r-- | src/find_desktop.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/find_desktop.c b/src/find_desktop.c index 4c33f2d..ca2004b 100644 --- a/src/find_desktop.c +++ b/src/find_desktop.c @@ -16,13 +16,14 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> -static int find_desktop(const char* display); +static char* find_desktop(const char* display, int use_prefix); int main(int argc, char** argv) { - int d = -1, a; + int a; const char* display = NULL; - int usage = 0, error = 0; + char* desktop; + int usage = 0, error = 0, prefix = 0; for (a = 1; a < argc; ++a) { if (argv[a][0] == '-') { if (strcmp(argv[a] + 1, "display") == 0) { @@ -32,6 +33,8 @@ int main(int argc, char** argv) } else { display = argv[a]; } + } else if (strcmp(argv[a] + 1, "prefix") == 0) { + prefix = 1; } else if (strcmp(argv[a] + 1, "help") == 0 || strcmp(argv[a] + 1, "-help") == 0) { usage = 1; @@ -47,6 +50,7 @@ int main(int argc, char** argv) fputs("\n", stdout); fputs("Options:\n", stdout); fputs(" -display <DISPLAY> X11 display to connect to instead of default\n", stdout); + fputs(" -prefix prefix display number with source\n", stdout); fputs(" -help display this text and exit\n", stdout); fputs("\n", stdout); return error ? EXIT_FAILURE : EXIT_SUCCESS; @@ -55,18 +59,20 @@ int main(int argc, char** argv) fputs("Try `find_desktop -help` for usage.\n", stdout); return EXIT_FAILURE; } - d = find_desktop(display); - if (d < 0) + desktop = find_desktop(display, prefix); + if (!desktop) { return EXIT_FAILURE; } - fprintf(stdout, "%d\n", d); + fprintf(stdout, "%s\n", desktop); + free(desktop); return EXIT_SUCCESS; } static int _get_from_e17_using_window(Display* dsp, Window wnd); +static char* create_desktop(const char* prefix, int desktop, int use_prefix); -int find_desktop(const char* display) +char* find_desktop(const char* display, int use_prefix) { Display* dsp = XOpenDisplay(display); Window root; @@ -79,7 +85,7 @@ int find_desktop(const char* display) const char* desktop_env; if (dsp == NULL) { fputs("Unable to open X11 display.\n", stderr); - return EXIT_FAILURE; + return NULL; } screen = DefaultScreen(dsp); @@ -97,7 +103,7 @@ int find_desktop(const char* display) int ret = ((long*)data)[0]; XFree(data); XCloseDisplay(dsp); - return ret; + return create_desktop("ewmh", ret, use_prefix); } } @@ -112,7 +118,7 @@ int find_desktop(const char* display) int ret = _get_from_e17_using_window(dsp, (Window)windowid); if (ret != -1) { XCloseDisplay(dsp); - return ret; + return create_desktop("enlightenment", ret, use_prefix); } } } @@ -132,13 +138,27 @@ int find_desktop(const char* display) XDestroyWindow(dsp, wnd); if (ret != -1) { XCloseDisplay(dsp); - return ret; + return create_desktop("enlightenment", ret, use_prefix); } } /* Don't know what else to do */ XCloseDisplay(dsp); - return -1; + return NULL; +} + +char* create_desktop(const char* prefix, int desktop, int use_prefix) +{ + if (use_prefix) { + size_t len = strlen(prefix) + 11; + char* ret = malloc(len); + snprintf(ret, len, "%s_%d", prefix, desktop); + return ret; + } else { + char* ret = malloc(10); + snprintf(ret, 10, "%d", desktop); + return ret; + } } static Atom __e_window_desk = 0; |
