Receive Signal for System Key using Linux? - c

I want to register my Application (its a Gtk Application) to receive a signal when the user presses for example the "Next Song" Button, while it is not focused, so the User can change the playback while the Application remains in the background. I have no idea how to do this - will I need to include a specific Library for doing this on Ubuntu 18.04? Just to clarify: I am talking about System-Wide Hotkeys that applications can somehow intercept.

There isn't really a generic mechanism for this in Wayland (the security issues should be pretty obvious); for X, see the XGrabKey function.
For multimedia keys, there is a D-Bus interface you can use at org.gnome.SettingsDaemon.MediaKeys. For an example of how to use it, take a look at plugins/nmkeys/rb-mmkeys-plugin.c in Rhythmbox.

Related

How can I determine whether a specific process is responsive?

I'm working on something that's basically a task manager. I have a working prototype but now I'd like to be able to show applications that are not responsive.
Are there APIs that can tell me whether this is the case under Window, macOS, Linux? I need to do this without the cooperation of the processes, so I can't just send a custom message and wait for a response.
Preferably C, but I can work with Obj-C & co.

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?

Read input device in C

I'm creating a 2-D platformer game in C that will run in the terminal. I need a way to register "KEY_DOWN" and "KEY_RELEASE" events. As far as I know getchar() reads from stdin and thus can not be used for registering "KEY_RELEASE" events. Neither can it be used for registering if multiple keys are being pressed down at the same time.
Is there a Mac OSX 10.10.5 C library that I can use to solve this problem? Maybe a library which reads input directly from the keyboard instead of the terminal?
None of the potential answers are likely to be simple:
if you are running an application in the terminal, and lacking (as OSX does) a set of system calls for reading the keyboard state directly, it won't work.
the available sources describe non-terminal applications (mostly using Cocoa, the OSX GUI, and mostly using ObjectiveC).
Here are a few:
How can I detect that the Shift key has been pressed?
Showing how to listen to all keypresses in OS X through the Cocoa API using Python and PyObjC
Listening for Global Keypresses in OSX
Mouse button and keypress counter for Mac OS X
OSX: Detect system-wide keyDown events?
For reference (Cocoa Event Handling Guide):
Handling Key Events
Monitoring Events

Programmatically disabling the screen blanker on X11 [duplicate]

X11 has a screensaver mechanism that can be controlled by xset command. Without having to invoke the external command to disable or heartbeat the screensaver, from inside my X11 application, how can I heartbeat the screensaver mechanism so to prevent it from shutting down the monitor?
If this on a modern Linux system, the preferred FreeDesktop method is to ping the DBus interface, specifically org.freedesktop.ScreenSaver.SimulateUserActivity() or another part of the exposed interface, depending on your needs.
As well as the D-Bus solution suggested by #Kitsune. You can also take the approach that some media players do and simulate the pressing of a key (e.g. Alt) at regular intervals.
This code in totem: http://git.gnome.org/browse/totem/tree/lib/totem-scrsaver.c is designed to be dropped into your code base (it's LGPL v2.1) and will use both the D-Bus interface and also use XTest to synthesize pressing the Alt key every 30s.

Detecting dropped call in Mobile

I'm using Motorola device and developed it with J2ME . I'm searching for a functionality to detect incomming or outcomming calls when dropped .
I mean , when the call is dropped I need to recognize this event.
Thanks
There is no standard J2ME telephony API.
There could be a working proprietary java-based API on that particular handset but that's both unlikely and not obvious to verify.
You could use the life-cycle of the application to detect interrupts. Your device can detect when a phone-call comes in and ends, and trigger shownotify(), hidenotify(), startApp(), pauseApp(), then do something accordingly. See the canvas class. So if you have an application running, you can detect an incoming phone-call, wait for it to end then do something. This is of course very device/manufacturer specific and you are in a world of hurt when it comes to porting this for many devices. I'm not sure if you can do something like this for outgoing calls, since your app will be in the background and paused for most devices.
You could try checking the motorola developer webpage. Motorola has its own set of libraries for j2me, it may support the case you need.

Resources