| 1 | #include "wm.h" |
| 2 | #include "common.h" |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | const char *display_wm() { |
| 9 | #if defined(__APPLE__) |
| 10 | return "Aqua"; |
| 11 | #elif defined(__HAIKU__) |
| 12 | return "Stack & Tile"; |
| 13 | #else |
| 14 | const char *display = run_command_s("echo $DISPLAY"); |
| 15 | if (display == NULL || strlen(display) == 0) return NULL; |
| 16 | else free((void *)display); |
| 17 | |
| 18 | const char *xproptest = run_command_s("xprop -root -notype _NET_SUPPORTING_WM_CHECK"); |
| 19 | if ( |
| 20 | strncmp( |
| 21 | xproptest, |
| 22 | "xprop: error: Invalid window id format: -notype.", |
| 23 | strlen("xprop: error: Invalid window id format: -notype.") |
| 24 | ) |
| 25 | ) return NULL; |
| 26 | else free((void *)xproptest); |
| 27 | |
| 28 | char cmd[512]; |
| 29 | const char *id = run_command_s("xprop -root -notype _NET_SUPPORTING_WM_CHECK | " |
| 30 | "awk '{print $5}'"); |
| 31 | |
| 32 | snprintf( |
| 33 | cmd, |
| 34 | sizeof(cmd), |
| 35 | "%s%s%s", |
| 36 | "xprop -id ", |
| 37 | id, |
| 38 | " -notype -len 100 -f _NET_WM_NAME 8t | awk '{print $3}' | head -1 | " |
| 39 | "sed 's/\"//g'" |
| 40 | ); |
| 41 | |
| 42 | free((void *)id); |
| 43 | |
| 44 | const char *wm = run_command_s(cmd); |
| 45 | |
| 46 | return wm; |
| 47 | #endif |
| 48 | return NULL; |
| 49 | } |