From 9ce54edb9cd08b98359df625853c5234d8982807 Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 01:00:47 +0700 Subject: [PATCH 1/6] (#26) Add a flag to enable windowed support back --- README.md | 8 +++++++- src/boomer.nim | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 640a52f..f9fbeb1 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,16 @@ See issue [#26]. For an experimental Live Update feature compile the application $ nimble build -d:live ``` +Live update feature makes more sense right now in the windowed mode to enabled windowed mode use the following flags: + +```console +$ nimble build -d:live -d:windowed +``` + For a faster Live Update feature based on MIT-SHM X11 extension use `-d:mitshm`: ```console -$ nimble build -d:live -d:mitshm +$ nimble build -d:live -d:windowed -d:mitshm ``` The MIT-SHM support would probably not work for you until diff --git a/src/boomer.nim b/src/boomer.nim index e0ad0a4..b48ff7b 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -182,8 +182,9 @@ proc main() = swa.event_mask = ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or PointerMotionMask or ExposureMask or ClientMessage - swa.override_redirect = 1 - swa.save_under = 1 + when not defined(windowed): + swa.override_redirect = 1 + swa.save_under = 1 var attributes: TXWindowAttributes discard XGetWindowAttributes( @@ -303,7 +304,8 @@ proc main() = let dt = 1.0 / rate.float while not quitting: # TODO(#78): Is there a better solution to keep the focus always on the window? - discard XSetInputFocus(display, win, RevertToParent, CurrentTime); + when not defined(windowed): + discard XSetInputFocus(display, win, RevertToParent, CurrentTime); var wa: TXWindowAttributes discard XGetWindowAttributes(display, win, addr wa) From 51ec0ee7c90e6b68d1f38a6cacbd8b5e7cd8a860 Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 02:23:23 +0700 Subject: [PATCH 2/6] Experimental window tracking support --- src/boomer.nim | 53 ++++++++++++++++++++++++++++++++++++++++------ src/screenshot.nim | 17 ++++++--------- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/boomer.nim b/src/boomer.nim index b48ff7b..afe6ef8 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -4,7 +4,13 @@ import navigation import screenshot import config -import x11/xlib, x11/x, x11/xutil, x11/keysym, x11/xrandr, x11/xshm +import x11/xlib, + x11/x, + x11/xutil, + x11/keysym, + x11/xrandr, + x11/xshm, + x11/cursorfont import opengl, opengl/glx import la @@ -128,6 +134,38 @@ proc getCursorPosition(display: PDisplay): Vec2f = result.x = root_x.float32 result.y = root_y.float32 +proc selectWindow(display: PDisplay): TWindow = + var cursor = XCreateFontCursor(display, XC_crosshair) + defer: discard XFreeCursor(display, cursor) + + var root = DefaultRootWindow(display) + discard XGrabPointer(display, root, 0, + ButtonMotionMask or + ButtonPressMask or + ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, + root, cursor, + CurrentTime) + defer: discard XUngrabPointer(display, CurrentTime) + + discard XGrabKeyboard(display, root, 0, + GrabModeAsync, GrabModeAsync, + CurrentTime) + defer: discard XUngrabKeyboard(display, CurrentTime) + + var event: TXEvent + while true: + discard XNextEvent(display, addr event) + case event.theType + of ButtonPress: + return event.xbutton.subwindow + of KeyPress: + return root + else: + discard + + return root + proc main() = var config = defaultConfig let @@ -147,9 +185,10 @@ proc main() = defer: discard XCloseDisplay(display) - var root = DefaultRootWindow(display) + echo "Please select window:" + var trackingWindow = selectWindow(display) - var screenConfig = XRRGetScreenInfo(display, root) + var screenConfig = XRRGetScreenInfo(display, DefaultRootWindow(display)) let rate = XRRConfigCurrentRate(screenConfig) echo "Screen rate: ", rate @@ -177,7 +216,7 @@ proc main() = echo "Visual ", vi.visualid, " selected" var swa: TXSetWindowAttributes - swa.colormap = XCreateColormap(display, root, + swa.colormap = XCreateColormap(display, DefaultRootWindow(display), vi.visual, AllocNone) swa.event_mask = ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or @@ -192,7 +231,7 @@ proc main() = DefaultRootWindow(display), addr attributes) var win = XCreateWindow( - display, root, + display, DefaultRootWindow(display), 0, 0, attributes.width.cuint, attributes.height.cuint, 0, vi.depth, InputOutput, vi.visual, CWColormap or CWEventMask or CWOverrideRedirect or CWSaveUnder, addr swa) @@ -220,7 +259,7 @@ proc main() = var shaderProgram = newShaderProgram(vertexShader, fragmentShader) - var screenshot = newScreenshot(display) + var screenshot = newScreenshot(display, trackingWindow) defer: screenshot.destroy(display) let w = screenshot.image.width.float32 @@ -415,7 +454,7 @@ proc main() = glFinish() when defined(live): - screenshot.refresh(display) + screenshot.refresh(display, trackingWindow) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB.GLint, diff --git a/src/screenshot.nim b/src/screenshot.nim index eef5b94..53ecd1f 100644 --- a/src/screenshot.nim +++ b/src/screenshot.nim @@ -36,10 +36,9 @@ type Screenshot* = object when defined(mitshm): shminfo*: PXShmSegmentInfo -proc newScreenshot*(display: PDisplay): Screenshot = - var root = DefaultRootWindow(display) +proc newScreenshot*(display: PDisplay, window: TWindow): Screenshot = var attributes: TXWindowAttributes - discard XGetWindowAttributes(display, root, addr attributes) + discard XGetWindowAttributes(display, window, addr attributes) when defined(mitshm): result.shminfo = cast[PXShmSegmentInfo]( @@ -70,28 +69,26 @@ proc newScreenshot*(display: PDisplay): Screenshot = discard XShmAttach(display, result.shminfo) discard XShmGetImage( - display, root, result.image, 0.cint, 0.cint, AllPlanes) + display, window, result.image, 0.cint, 0.cint, AllPlanes) else: result.image = XGetImage( - display, root, + display, window, 0, 0, attributes.width.cuint, attributes.height.cuint, AllPlanes, ZPixmap) -proc refresh*(screenshot: var Screenshot, display: PDisplay) = - var root = DefaultRootWindow(display) - +proc refresh*(screenshot: var Screenshot, display: PDisplay, window: TWindow) = when defined(mitshm): discard XShmGetImage( display, - root, screenshot.image, + window, screenshot.image, 0.cint, 0.cint, AllPlanes) else: screenshot.image = XGetSubImage( - display, root, + display, window, 0, 0, screenshot.image.width.cuint, screenshot.image.height.cuint, From fbeadeb0c4093fa9a8147599fadc9772bfe4afaa Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 02:31:20 +0700 Subject: [PATCH 3/6] (#26) TODOs --- src/screenshot.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/screenshot.nim b/src/screenshot.nim index 53ecd1f..89475e8 100644 --- a/src/screenshot.nim +++ b/src/screenshot.nim @@ -81,12 +81,14 @@ proc newScreenshot*(display: PDisplay, window: TWindow): Screenshot = proc refresh*(screenshot: var Screenshot, display: PDisplay, window: TWindow) = when defined(mitshm): + # TODO: MITSHM live update does not support window resizing discard XShmGetImage( display, window, screenshot.image, 0.cint, 0.cint, AllPlanes) else: + # TODO: XGetImage live update does not support window resizing screenshot.image = XGetSubImage( display, window, 0, 0, From 9416175288cee12eed9783ac5a5e484eeefb2ebc Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 08:03:55 +0700 Subject: [PATCH 4/6] (#26) Put window selection feature under experimental flag --- README.md | 30 ++++++++---------------------- src/boomer.nim | 8 ++++++-- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f9fbeb1..8ce42ed 100644 --- a/README.md +++ b/README.md @@ -31,30 +31,16 @@ $ nimble build -d:developer This will enable: - Reloading the shaders with `Ctrl+R` -## Experimental Live Update +## Experimental Features Compilation Flags -See issue [#26]. For an experimental Live Update feature compile the application with the following flags: +Experimental or unstable features can be enabled by passing the following flags to `nimble build` command: -```console -$ nimble build -d:live -``` - -Live update feature makes more sense right now in the windowed mode to enabled windowed mode use the following flags: - -```console -$ nimble build -d:live -d:windowed -``` - -For a faster Live Update feature based on MIT-SHM X11 extension use `-d:mitshm`: - -```console -$ nimble build -d:live -d:windowed -d:mitshm -``` - -The MIT-SHM support would probably not work for you until -[nim-lang/x11#31](https://github.com/nim-lang/x11/pull/31) is merged. - -The feature is really unstable and experimental, so use it at your own risk. +| Flag | Description | +|---------------|--------------------------------------------------------------------------------------------------------------------------------| +| `-d:live` | Live image update. See issue [#26]. | +| `-d:mitshm` | Enables fater Live image update using MIT-SHM X11 extension. Should be used along with `-d:live` to have an effect | +| `-d:windowed` | Run boomer in windowed mode instead of fullscreen. | +| `-d:select` | Application lets the user to click on te window to "track" and it will track that specific window instead of the whole screen. | ## NixOS Overlay diff --git a/src/boomer.nim b/src/boomer.nim index afe6ef8..7f783f7 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -185,8 +185,12 @@ proc main() = defer: discard XCloseDisplay(display) - echo "Please select window:" - var trackingWindow = selectWindow(display) + + when defined(select): + echo "Please select window:" + var trackingWindow = selectWindow(display) + else: + var trackingWindow = DefaultRootWindow(display) var screenConfig = XRRGetScreenInfo(display, DefaultRootWindow(display)) let rate = XRRConfigCurrentRate(screenConfig) From 907c7a27e02f470a72761aee5dcfb0d4d808431e Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 08:04:44 +0700 Subject: [PATCH 5/6] Add TODO(#83) --- src/screenshot.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screenshot.nim b/src/screenshot.nim index 89475e8..7a268b6 100644 --- a/src/screenshot.nim +++ b/src/screenshot.nim @@ -81,7 +81,7 @@ proc newScreenshot*(display: PDisplay, window: TWindow): Screenshot = proc refresh*(screenshot: var Screenshot, display: PDisplay, window: TWindow) = when defined(mitshm): - # TODO: MITSHM live update does not support window resizing + # TODO(#83): MITSHM live update does not support window resizing discard XShmGetImage( display, window, screenshot.image, From 73b23f3b6fea65ae320ca52351659f86a9ea39b9 Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 26 Dec 2019 08:04:45 +0700 Subject: [PATCH 6/6] Add TODO(#84) --- src/screenshot.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screenshot.nim b/src/screenshot.nim index 7a268b6..eeab6f1 100644 --- a/src/screenshot.nim +++ b/src/screenshot.nim @@ -88,7 +88,7 @@ proc refresh*(screenshot: var Screenshot, display: PDisplay, window: TWindow) = 0.cint, 0.cint, AllPlanes) else: - # TODO: XGetImage live update does not support window resizing + # TODO(#84): XGetImage live update does not support window resizing screenshot.image = XGetSubImage( display, window, 0, 0,