3

I am on Ubuntu 14.04 platform, I am trying to make a rubberband for my screencasting project. I found rubberbanding examples which used xlib but I got flickering and partially missing rectangle while dragging mouse. I wonder if it's specific to my system or xlib library deprecated? Is there a workaround to fix it?

I also noticed that imagemagic's screen location grabbing command import window.miff flickers the same way.

flickering rectangle

Here are the codes that I tried

xruler

xrectsel

kenn
  • 319
  • 12
  • 22
  • 2
    It just looks like the terminal in the background is repainting itself. You could always be selfish, and do an `XGrabServer()`, which WMs that use rectangles when moving/resizing windows do. Nothing else on the screen (clocks, load monitors) will update until you release the grab. – ninjalj Aug 07 '14 at 23:26
  • @ninjalj Thanks a lot! Putting `XGrabServer(disp)` before `XDrawRectangle()` works. Would you post it as an answer? It might be helpful to others. – kenn Aug 08 '14 at 09:18

2 Answers2

4

It just looks like the terminal in the background is repainting itself. You could always be selfish, and do an XGrabServer(), which WMs that use rectangles when moving/resizing windows do. Nothing else on the screen (clocks, load monitors) will update until you release the grab.

Server grabs should be avoided. You may want to add a --grab/--nograb option to let the user decide whether they prefer avoiding visual artifacts or let other applications (movie players, load monitors, clocks, ...) update the screen during the rubberbanding.

Another option would be to use a translucent window instead of an outlined rectangle, similar to how modern window managers tend to move/resize windows using real windows instead of rubberbands (even when that probably means repainting the window a lot of times before the operation is finished, for remote X move/resize with rubberbands is definitely better behaved).

Examples of XGrabServer() being obnoxious:

ninjalj
  • 39,486
  • 8
  • 94
  • 141
  • I also tried to find glut based rubberbanding examples, I found a few of them but all of them has window decorator. I was unable to remove window decorator, it appears to be hard to do that in glut. Here is my glut question http://stackoverflow.com/questions/24839233/select-a-screen-area-with-mouse-and-return-coordinates-in-glut – kenn Aug 08 '14 at 10:53
1

If you use xor in your GC you can selectively erase lines by drawing exactly the same thing again. You don't need to repaint the whole window.

XSetFunction(dpy,gc,GXxor); // sets xor mode

Just set up some buffers and keep a copy of what you draw so you can do it again (including the color).

I wrote this last year: https://www.raspberrypi.org/forums/viewtopic.php?p=1317849 I store the last 50 lines in a circular buffer then redraw them to erase. I can run it for hours with no incomplete erasure artifacts. And very low CPU usage. It's almost xscreensaver quality. enter image description here

Alan Corey
  • 419
  • 3
  • 9