Skip to content

Commit

Permalink
Bring to front linux (#165)
Browse files Browse the repository at this point in the history
* Implement bring-to-front for Linux

* Add musl-64 binary

* Add glibc-64 binary

* Add glibc-32 binary

* Add musl-32 binary
  • Loading branch information
AndreyBelym authored Apr 5, 2019
1 parent 6374659 commit 283e1f1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 1 deletion.
Binary file added bin/linux/glibc-32/bring-to-front
Binary file not shown.
Binary file added bin/linux/glibc-64/bring-to-front
Binary file not shown.
Binary file added bin/linux/musl-32/bring-to-front
Binary file not shown.
Binary file added bin/linux/musl-64/bring-to-front
Binary file not shown.
2 changes: 2 additions & 0 deletions src/api/bring-to-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default async function (windowDescriptor) {

if (OS.win)
bringWindowToFrontArguments = [windowDescription.hwnd];
if (OS.linux)
bringWindowToFrontArguments = [windowDescription.windowId];
else if (OS.mac)
bringWindowToFrontArguments = [windowDescription.processId, windowDescription.windowId];
else
Expand Down
3 changes: 2 additions & 1 deletion src/binaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ else if (OS.linux) {
resize: toAbsPath(`../bin/linux/${platform}/resize`),
maximize: toAbsPath(`../bin/linux/${platform}/maximize`),
screenshot: toAbsPath(`../bin/linux/${platform}/screenshot`),
generateThumbnail: toAbsPath(`../bin/linux/${platform}/generate-thumbnail`)
generateThumbnail: toAbsPath(`../bin/linux/${platform}/generate-thumbnail`),
bringToFront: toAbsPath(`../bin/linux/${platform}/bring-to-front`)
};
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/natives/bring-to-front/linux/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all: clean build
clean:
rm "${DEST}/bring-to-front" || true
build:
mkdir "${DEST}" || true
${CXX} bring-to-front.cpp -I/usr/include/X11 -L/usr/lib/X11 -lX11 -o "${DEST}/bring-to-front"
59 changes: 59 additions & 0 deletions src/natives/bring-to-front/linux/bring-to-front.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <cstdio>

extern "C" {
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
}

int main (int argc, char** argv) {
if (argc != 2) {
printf("Incorrect arguments\n");
return 1;
}

unsigned long windowId = 0;

sscanf(argv[1], "%lx", &windowId);

Display* display = XOpenDisplay(NULL);

if (display == NULL) {
printf("Cannot open display\n");
return 1;
}

XWindowAttributes attr;

Atom atom = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);;
XEvent xev;

xev.xclient.type = ClientMessage;
xev.xclient.serial = 0;
xev.xclient.send_event = True;
xev.xclient.display = display;
xev.xclient.window = (Window) windowId;
xev.xclient.message_type = atom;
xev.xclient.format = 32;
xev.xclient.data.l[0] = 2;
xev.xclient.data.l[1] = 0;
xev.xclient.data.l[2] = 0;
xev.xclient.data.l[3] = 0;
xev.xclient.data.l[4] = 0;

XGetWindowAttributes(display, (Window) windowId, &attr);

XSendEvent (display,
attr.root, False,
SubstructureRedirectMask | SubstructureNotifyMask,
&xev);

XSync(display, False);

XRaiseWindow(display, (Window) windowId);
XSync(display, False);

XCloseDisplay(display);

return 0;
}

0 comments on commit 283e1f1

Please sign in to comment.