How to properly use XMaskEvent() function? - cygwin

I am programming a GUI in plain C using X11 library, on Cygwin. When trying to read cursor movements over an open window using XMaskEvent() it works like a charm. It returns an XEvent structure whose coordinates point to the current mouse location and the event_type is a small positive integer number that corresponds to what happened (mouse move, button press, button release etc). So far so good. The problem is that this command blocks (it is supposed to) after each mouse move or button event so my program cannot do anything continuous.
So I tried to replace XMaskEvent() with XCheckMaskEvent() which should read an event, remove it from the queue and continue, so that my program can continue doing something. However, XCheckMaskEvent returns an event with zero coordinates, and constant crazy event_type of minus million-something. Whatever i do with the mouse or keyboard, I am always getting an empty event of a crazy type.
I am using the same event mask for both commands.
What am I doing wrong?

Related

how to draw a cursor in glfw while getting mouse input?

I have a program using glfw for window management and opengl for rendering. The program works on Windows and linux, and eventually Mac OSX so I want any solution to be portable.
glfw seems to either support a cursor, or getting full mouse input but not both. For example, with the cursor enabled (default) the glfwscroll_callback does nothing. If I disable the cursor, then scrolling the mouse is captured but then the user cannot see where the mouse pointer is. That's ok if I can draw the cursor myself when I want but I cannot find any function to drawcursor at a particular location.
How does the cursor work, ie what is the hardware basis for the cursor? Is there a sprite in hardware still? If it's all in software, I suppose we could draw a cursor at the current mouse location the last thing in render. But that's not convenient. For one thing if the scene hasn't changed, I shut down rendering completely to reduce power.
Is there any way to manually draw a cursor on top of the current screen so that we don't have to manage the buffers manually? Is my only option to change the logic and not render the scene if nothing has changed, but to manually draw a cursor on top of the current scene every frame?

How to move window offscreen with wmctrl

I am trying to programmatically move a window so that it is partially on screen. For instance, clicking the VLC title bar and dragging it so that only half the window is visible works just fine.
When I output the results of wmctrl -lG this works just fine:
0x04a00011 0 -293 138 600 420 HEVM002 VLC media player
However, when I then move it back on screen and try and replicate its position, it doesn't work and clips the window to the far side:
wmctrl -r "VLC media player" -e 0,-200,0,800,600
I have tested on a couple of window managers, and it seems to work fine on xfwm but NOT on compiz. Is there a flag or something like that I can set to enable moving windows off-screen?
When running under a window manager, this is entirely up to the window manager. Whether there is a flag to force partial off-screen positions depends on which window manager it is.
The only window manager agnostic way of achieving this is making the window an override_redirect window. But, of course, this means the window is no longer managed. Making it a normal window again will cause the window manager to manage it again which likely, again depending on the window manager, means forcing it to be in-bounds again.
That said, looking at wmctrl's source code, it uses _NET_MOVERESIZE_WINDOW if supported by the window manager and falls back to XMoveResizeWindow (or similar) otherwise. However, in the first case it casts the position values to unsigned long first which effectively means any negative values will be lost anyway. In the second case, negative values seem to signal "don't move", so no luck there either.
You could try using xdotool windowmove instead which will deal with negative values correctly. Maybe also consider filing a bug against wmctrl?

Propagating all events from a X window

I'a currently working on a small utility, it's my first ever X project. The utility is used to draw a small circle around your mouse pointer. I use an app called Pinpoint to do the same on my Mac, it helps me find my mouse as I'm visually impaired.
The utility creates an transparent X window and draw a circle inside, it then moves that window with the mouse pointer so that the circle follows the mouse.
It currently works, except for one detail. Mouse events are not propagated up to the underlying windows. Basically, the utility makes the mouse useless.
As far as I can tell from the Xlib docs, if not otherwise specified, new windows should propagate all events. How can I fix this?
The code can be found on GitHub: https://github.com/blubber/circle-cursor it's a bit messy currently, becaue it is just a proof of concept.
I would suggest doing via cursor image as well, there are many ways when you won't be able to receive mouse events and only possible source would be polling with XQueryPointer.
With xfixes extension you can subscribe to all cursor image changed events and get most recent shape of the cursor, and whit XRender you can set your own ( possibly animated cursor )

How can add space-key to jump for Platform behavior in construct 2?

I'm using the Platform Behavior in Construct 2 for a Windows 10 game. In addition to the arrow key, I would like to use the Space bar to get the sprite to jump. Can I tell it to call into the Platform behavior somehow or get it to let me map space bar as well as up arrow to 'jump'?
You certainly can. You can use an action called "Simulate Control" to simulate pressing left, right, or up. So as your event, use Keyboard->on Key Pressed (Space Bar). Then for the action Player->Simulate Control (Up Arrow). This will allow you to press space bar to have your character jump. Additionally, you can turn off default controls for the platform behavior and do custom controls for left, right, and up using the same strategy.
The best way to go about doing this is by adding an event that handles the Space Button. Make sure to add the keyboard object in your layout, and in the event sheet, you want to make an event that handles the keyboard -> on key pressed (choose the spacebar when asked) -> choose whatever object you want to jump with the Platform behavior -> Set Vector Y to whatever increment you'd like to jump. Be sure to list this value as negative. The y-axis in C2 is inverted, so negative numbers mean up.
Hope this helps!

UIKeyboardFrameBeginUserInfoKey/UIKeyboardFrameEndUserInfoKey: what is the difference?

It is possible to read the following in the apple Documentation:
UIKeyboardFrameBeginUserInfoKey
The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard ……
UIKeyboardFrameEndUserInfoKey
The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard ……
Would that mean that the keyboard has a "start frame" and an "end frame"?
I suppose YES.
But when the keyboard appears I cannot see any frame changing. It just stays the same frome start to end.
So my question is:
What are those "start frame" and "end frame" referring to?
I must be missing something.
Thanks for your help.
The keyboard does indeed have a start and end frame, and the properties do exactly what you suppose they do. They keyboard does not always animate however; sometimes it just appears or changes size. For example, in the case that you are typing on the Japanese keyboard, when the keyboardWillShow fires after the first character is hit. There's no animation, but an additional bar appears above the keyboard, thus changing the size. The properties you listed above tell you how much the keyboard changed size by.
I'm not sure what exactly you're looking at when you say no frames are changing. I suppose it's possible that when you move from one editable text field to another, you get a keyboardWillShow notification, even though nothing on the screen changes.

Resources