xlib

Equivalent of “Invalidate Rect” / “WM_PAINT” in X11

China☆狼群 提交于 2019-11-30 02:40:45
问题 I'm Porting some code from Windows to XLib. In the windows code, I can force a redraw by calling InvalidateRect and then handling the corresponding WM_PAINT message. However, I am having trouble finding out how to do this in X11/XLib. I see there is an Expose message but not sure if that is the same thing. If it matters, I need to do this to force the window to render at a certain frame rate for an OpenGL based program. 回答1: You need to handle Expose events. This tutorial explains with an

Does xlib have an active window event?

狂风中的少年 提交于 2019-11-29 23:50:38
问题 I am trying to write a program that tracks when the active window changes using Xlib. I am have trouble figuring out the best way to do this. These are my ideas so far: Every second use _NET_ACTIVE_WINDOW to get the active window and if it has changed then running the related code for the event. Get a list of all windows and listen to their focus in event. I would have to figure out how to keep an up to date list of open windows though. Is their an easier/better way? I am new to programming

X11 Mouse Movement Event

大兔子大兔子 提交于 2019-11-29 21:15:26
问题 When creating a Window in XLib What are the masks I provide to the SetWindowAttributes.event_mask member? What do I have to pass to the 11th paramater of XCreateWindow() What are the Events I am looking for in the main message loop (Where I use XNextEvent(lDisplay, &xEvent); ? Since X behaves differently than Microsoft's Win32 API, how do I determine if the mouse is over my window or a window in my "Application" and not over the desktop? I have looked for a similar post. If there is already

Embed an app into a window

怎甘沉沦 提交于 2019-11-29 20:13:28
问题 FvwmButtons (a module of fvwm window manager) has the Swallow function, that embeds the window of an application into a panel. I have to do something like this with Motif and Xlib. I want to embed an Xclock into my application. I guess I have to change the Window ID of the embedded app. How can I do that? 回答1: the only supported and reliable mechanism is XEmbed, but it requires the embedded app to cooperate. Without a cooperating app, you're in a world of scary hacks. The basic thing you need

Screenshots in X11

风格不统一 提交于 2019-11-29 15:32:31
问题 What functions would one use to take a screenshot of an X11 desktop, using the Xlib library? I would prefer a method that's more efficient than getting individual pixels. Thanks. 回答1: The standard tool for taking screenshots in X11 is to use xwd -root > myscreen.xwd Then, convert to .pnm with xwd2pnm myscreen.xwd > myscreen.pnm Therefore, you can locate the source code of xwd and see how it is implemented, http://cvsweb.xfree86.org/cvsweb/xc/programs/xwd/xwd.c?rev=HEAD&content-type=text/vnd

How to create a game loop with xlib

不羁岁月 提交于 2019-11-29 15:31:57
I am trying to create a game loop for an xlib window, but I cannot manage to paint the window correctly. Right now I am creating a window with XCreateSimpleWindow(...), and using a for loop to paint all pixels one at a time. (The color of these pixels is read from a large integer array, for now I've set all pixels to be blue.) The actual game loop right now is the following: void loop() { while (true) { // Clear the window (the background color is set to white) XClearWindow(dsp, win); // Loop through all pixels of the 800*600 window for (int j = 0; j < 600; j++) { for (int i = 0; i < 800; i++)

X11/Xlib: Create “GlassPane”-Window

喜夏-厌秋 提交于 2019-11-29 15:06:03
问题 I've tried to create a fully transparent window using C++ & X11. It should not consume any events and simply forwards them to the windows below. Some kind of GlassPane as it's known for Java-Windows, but full screen. Then I'd like to draw on this window. Is this somehow possible with X11? My first attempt was ignoring all events, simply copy the image from the root window using XGetImage() ... But first of all, this is quite slow as the window would need to be full screen. XShmGetImage

How a draw a string in a splash screen by Xlib

僤鯓⒐⒋嵵緔 提交于 2019-11-29 12:50:38
here is my code and I can not jump out of the while(!done) function use XFlush(d) can show the display form buffer and do not disappear before XCloseDisplay(d) and I want to make draw string like that g++ -o youname youcppname -lX11 #include <X11/Xlib.h> #include <X11/Xatom.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { Display *d; Window w; XEvent e; const char *msg = "Hello, World!"; int s; bool done = false; /* open connection with the server */ d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } s

How to create semi transparent white window in XLib

泪湿孤枕 提交于 2019-11-29 12:11:24
I would like to create a semi transparent white window in XLib, but the window is not semi translucent, it remains fully opaque. I use the compton compositor and there are transparent windows in the system, so the problem is in the code: #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdio.h> int main(int argc, char* argv[]) { Display* display = XOpenDisplay(NULL); XVisualInfo vinfo; XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); attr

getting mouseclick coordinates with Xlib

不羁的心 提交于 2019-11-29 11:47:04
I would like to know how to get the x and y coordinates of a mouseclick with Xlib anywhere on the screen. I've found this post which gets the current pointer position How can I get the current mouse (pointer) position co-ordinates in X , but I don't know how to modify it so it gets the x y coordinates when the mouse is clicked. I've tried to write this code but it does nothing. #include <stdio.h> #include <stdlib.h> #include <X11/Xlib.h> #include <X11/Xutil.h> int main (){ int x=-1,y=-1; XEvent event; int button; Display *display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr,