How do take a screenshot correctly with xlib?

You are mistaken about the way array is laid out in memory, as you can find out by declaring img before the loop and adding this printf to your inner loop: printf(“%ld %ld %u %u %u\n”,x,y,pic.offset(x,y,0),pic.offset(x,y,1),pic.offset(x,y,2)); This yields (on my 1920×1200 screen): 0 0 0 2304000 4608000 0 1 1920 2305920 4609920 0 2 3840 … Read more

Global Hotkey with X11/Xlib

Your program works here. My guess is you have another modifier active, such as NumLock. GrabKey only works on the exact modifier mask. For example here is some (GPL) code from metacity window manager /* Grab/ungrab, ignoring all annoying modifiers like NumLock etc. */ static void meta_change_keygrab (MetaDisplay *display, Window xwindow, gboolean grab, int keysym, … Read more

How do I gracefully exit an X11 event loop?

The problem lays in the communication between X Server and the Window Manager. When you call XCreateWindow or XCreateSimpleWindow, the X Server creates your window (not showing it until you explicitly map it on the screen by calling XMapWindow), and then the Window Manager is responsible for attaching all the decorations and buttons and system … Read more

How do I efficiently determine if a polygon is convex, non-convex or complex?

You can make things a lot easier than the Gift-Wrapping Algorithm… that’s a good answer when you have a set of points w/o any particular boundary and need to find the convex hull. In contrast, consider the case where the polygon is not self-intersecting, and it consists of a set of points in a list … Read more

Xlib and Firefox behavior

This question is ancient but for the benefit of anyone who stumbles across it looking for an answer to this, here’s an edited (chopped to bits) sample of how I solved this based on the hints above: while (event = xcb_poll_for_event(connection)) { uint8_t actual_event = event->response_type & 127; switch (actual_event) { case XCB_MAP_NOTIFY: ; xcb_map_notify_event_t … Read more