Programmatically disabling the screen blanker on X11 [duplicate] - c

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.

Related

What's the relationship between AT commands and device vendor's C API?

I'm doing an embedded-system project now. From my view, AT commands can be sent to a device to retrieve 4G information, dial and so on. On the other hand, we can also do that by calling APIs provided by the 4G vendor.
My question is what's the relationship between them? Is the API a wrapper for the AT commands?
TL;DR
Vendor's API (not only C, but also C++, Java or Python depending to the vendor and the modem model) can both be wrappers for AT commands and a wider, more powerful set of API were the user can port complex applications.
It depends on the vendor and on the model.
A jungle of modems produced by different vendors
It is impossible to define a general "rule" about API provided by a Cellular Module (not necessarily a 4G module).
First of all every vendor usually implements standard AT Commands (both Hayes commands and extended standard commands for cellular devices). In the same way every vendor has it's own implementation of the user application area where the customers can store their own application to control the modem's functionalities and to use them according to their own application requirements.
AT commands remain the interface to be used when the modem needs to be connected (and driven) by an external host. When the user application area is used, instead, a wider set of API is usually provided. They may include:
A library exporting a subset of the OS capabilities (threads management, events, semaphores, mutexes, SW timers, FS access and so on)
A library offering the capability to manage the specific HW of the device (GPIOs, SPI, I2C, ADC, DAC and so on)
A library offering a programmatical way to perform action, related to connectivity, that would normally be executed through AT commands (registration status check, PIN code insertion, PDP context activation, SMS management, TCP/UDP/TLS sockets)
The latter usually access a base layer involving all the functionalities provided by the modem. Usually this is the same layer invoked by the AT commands sent through modem's serial interface.
Sending AT commands... from the vendor's API?
Of course it often happens that the library mentioned above provides just a subset of the functionalities usually exported with the AT commands set so, in order to "fill the gap", a further set of APIs is usually exported as well:
A set of functions that allow the simulation of AT commands sent to the modem's serial port. Sending them and parsering the responses they send in the vitual internal serial/USB interface allow the user to port in the internal user application area the the application they previously run on an external host processor (with obvious BOM benefits).
As an example, please check Telit Appzone here and here. It was the inspiration of my answer because I know it very well.
I don't know why you name the title that there's a relationship between AT command and Linux-C API.
Regarding AT command, you can take a look at this wiki article for general information.
Each module has a specified AT command sets. Normally, the module manufacture just offers AT command set and what return values are.
Is API a wrapper of AT command?
If you can use the API provided by the manufacturer, then yes, it's a wrapper of the AT command handler.
My question is what's the relationship between them? Is the API a wrapper for the AT commands?
It is impossible to be sure without having any details of the device, but probably any C API for it wraps the AT command set, either by communicating with the device directly over an internal serial interface or by going through a device driver that uses AT commands to communicate with it.
However, it is at least conceivable, albeit unlikely, that the 4G device offers an alternative control path that the C API uses (definitely via a driver in this case).
I'm not quite sure what the point of the question is, though. If you are programming the device and its 4G component in C, and the manufacturer has provided a C API, then use it! If you are programming in some other language then at least consider using the C API, which you should be able to access from most other languages in some language-specific way. You should not expend effort on rolling your own without a compelling reason to reject the API already provided to you.

Receive Signal for System Key using Linux?

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.

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

How to make a Windows touch pad acts like a Mac touch pad?

I am trying to write something for windows using WINAPI, so I can make the touch pad do whatever the mac touch pad do.
I have checked using Spy++ what WM messages the two finger taps and etc. send to the OS, but figured out it sends only those plus/minus:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_MOUSEHOVER
WM_MOUSEHWHEEL
WM_MOUSELEAVE
WM_MOUSEMOVE
WM_RBUTTONDOWN
WM_RBUTTONUP
When I tried to see what happend when clicking with 3 or 2 fingers it didn't send any particular message, unless I moved them a bit.
firstly i would like to start with this:
when 5 fingers going down show desktop (as win+D does).
How to write (driver?) something that can diagnose 5 fingers touching simultaneously the touch pad?
Of curse there is no OS messages for this, but I can make some unique combination of existed messages and by that diganose it.
If I need to write a driver can I do it generic for most of the touchpad, can I do it as add-on?
If you can post a good tutorial you are familiar with for writing a driver for windows, pls, cause I have no clue about it.
Do I need anything else to take into account :
1. Diagnose 5 fingers mouse events.
2. Make a thread in Explorer on startup that handle those new mouse messages.
thanks in advance
Mouse Input Notifications
In short, you can't.
First, there are touchpads that can physically detect only 1 finger touch, and for those who can detect many - their drivers do the translation for you.
Windows does not have any inherent support for reading multiple touch inputs - it relies on the touchpad drivers to provide them.
You can achieve your goal for SOME devices by writing your own touchpad driver (probably starting from Linux touchpad drivers and Windows driver development kit), but this is far from being simple.
And, you'll need to do this for each and every touchpad device you want to support (from Synaptics, Alps Electric, Cirque to name the few)
Only after that you can move on to implementing the reaction for the touchpad actions in applications like Explorer.

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