How do I lock the screen in x11 - c

I am trying to write a tiny x11 screen locker program (something like i3lock) in c. When the program is run it spawns a full screen window. I want this window to intercept all keyboard input preventing the user from leaving until they have entered the password. How would I go about intercepting the keyboard input and preventing the user from leaving?
Any help would be much appreciated, thanks.

Related

what is required to get an overlay window using x11 protocol with no compositor running?

Using the lisp implementation of the X11 protocol, get-overlay-window freezes when no compositor is running. If I kill the lisp process, the xid is printed out.
This also freezes my lisp window manager running in another lisp thread, though same process. Basically X acts like it's been grabbed, so thank god for ctrl-alt-f1.
Some previous questions about composite show others running into similar problems when no compositor is running.
I'm guessing that maybe the server is waiting for some sort of out of protocol authorization or something? Or something particular sequence of events has to be completed?
Having access to the overlay window when another compositor is active isn't helpful for writing a compositor!
Apparently I had a reading comprehension fail with the protocol description, or they a writing fail.
Asking composite to redirect windows automatically ensures the windows contents get drawn. It does not ensure they get drawn to the overlay! Nor does the overlay appear to be transparent. So even with setting all windows to be automatically updated, when the overlay window gets mapped by the call to get its XID it blocks you from seeing any other updates to the screen and blocks all input.
Making the overlay in a sense not very useful. Or the request to have automatic updates for redirected windows not useful. Either way, seems will have to paint every single pixel even of the windows we're not interested in.
Maybe it's just a driver thing?

Conclusively Detect a Process losing Focus [duplicate]

I've written a win32 App in C++ (a game) and I want to be able to know if the application has lost focus due to the user pressing CTRL-ALT-DEL and starting the task manager. How can I do this? What I want to do after detecting the event is to minimize the window of my game and pause its processing (animations, audio, etc.). However, if the user returns from the CTRL-ALT-DEL menu to the game then it should keep running as usual. I've thought that I could check for key presses on CTRL, ALT and DEL but that doesn't seem to work and just reacting to the lost the focus (WM_KILLFOCUS) is not what I want.
You can use WTSRegisterSessionNotification(), you'll get the WM_WTSSESSION_CHANGE message when the user presses Ctrl+Alt+Del and switches to the secure desktop.
Beware that you cannot tell that it was actually the secure desktop that he switched to, that would be rather nasty security leak. You'll also get the notification when he switches to another logon session. Also a case where you want to stop your game of course.
For that matter, a game ought to automatically pause whenever the game window loses the foreground. Nobody likes to be killed when they switch to their email reader :) Use the WM_ACTIVATEAPP message

Does the terminal driver buffer store the characters a user types? If so, how can one access those?

I'm writing a multi-threaded chat program in C, and if I'm typing in something and at the same time receive any message, it puts this message in front of what I was typing, messing up with my input. So yeah, is there any way to access the characters a user has just typed in if he hasn't pressed enter yet?
Yes, there is. If you put the terminal into raw mode, you'll get everything directly, instead of line-by-line processed by the terminal driver. However, if you're going to go that route, you're much better off learning how to use Curses or some similar terminal control library, rather than trying to manage the terminal directly.

Using multiple threads with the console

I am using pthreads to create an multithreaded application (in this case a chat client - that mostly works, actually.)
The problem I have is that I have one thread trying to read and the other thread trying to print to the same console window.
For example if the user types in something to the console, but receives a message from the other thread, another, he could be looking at somethinganother - but when he presses enter the only data he submits is something!
Could anyone be so kind as to tell me how to deal with this?

Receiving asynchronous user and external input using ncurses

I'm making a 2-player game which is controlled by a player from keyboard and at the same time receives input from a server program using message queues. Initially I tried to implement the player console in the parent process and make a child process to react to messages from the server, but every time I modified the screen with the child process it deleted all the changes I made in the parent process - in other words, the processes had separate screens. It looks like there has to be one process which manages both the keyboard input and the server input, but I have no idea how to do this asynchronously.
Does anyone know how to do it? Alternatively, what other libraries could I use to make a game like that with a GUI?
OK, if anyone's interested, I have the solution. I used the STDIN_FILENO stream from unistd.h and the poll function to read data from both the keyboard and the pipe which informs about messages from the server.

Resources