-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathswallow.cpp
More file actions
57 lines (43 loc) · 1.07 KB
/
swallow.cpp
File metadata and controls
57 lines (43 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <X11/Xlib.h>
#include <cstdlib>
#include <iostream>
#include <string>
void usage() {
std::cout << "swallow app_name [arguments]\n";
}
int main(int argc, char** argv) {
if (argc <= 1) {
usage();
return 0;
}
std::string command;
for (int i = 1; i < argc; i++) {
command += argv[i];
command += ' ';
}
// open current display
int rev;
Window win;
Display* dis = XOpenDisplay(0);
if (dis == nullptr) {
std::cerr << "Failed to open display!\n";
return 0;
}
/*
* when this program runs the terminal emulator
* is the current focused window
*/
// hide the focused window
XGetInputFocus(dis, &win, &rev);
XUnmapWindow(dis, win);
XFlush(dis);
// launch the application
int res = system(command.c_str());
if (res != 0) {
std::cerr << "Application exited with " << res << "\n";
}
// the application exited
// unhide the terminal emulator
XMapWindow(dis, win);
XCloseDisplay(dis);
}