Supose my Qt application is running in background and I want to wake up the operating system when the screen saver is active or the monitor is blank for energy saving.
Is there any way to do it under Linux? concretely I would like to do it for a Raspberry Pi under Raspbian but a cross-platform method using Qt will be better.
I'm not sure if you're ok with it never going into sleep mode in the first place, but this is what I use:
sudo leafpad /etc/kbd/config
change BLANK_TIME=0
change POWERDOWN_TIME=0
sudo leafpad /etc/xdg/lxsession/LXDE-pi/autostart
Add line: #xset s noblank
Add line: #xset s off
Add line: #xset -dpms
Edit Just realized how old this question was. I hope I ended your 20 months of waiting and page refreshing.
Related
I try to ask here if somebody has encountered such a problem.
From time to time, I have a situation: I launch my Qt app on Windows (in debug mode, but I am not sure if it matters) via cmd.exe and then I work with it and then I stop working with it for some time. Then I return it to be focused and very rarely I experience this: the app is Not Responding even though I do not have any logic for it to react on being returned to be focused. Then I wait and wait and noting happens and then I press any key in my cmd.exe, and instead of being killed, my app suddenly wakes up and continues to work, and then I do not experience any problems anymore.
What can be the problem? On Linux I do not experience such a problem. I ask because I cannot trace the problem, as it happens not very often. Also, I am not very good acquainted with Windows. If it was Linux I would use gdp -p and try to see where the app hangs. But what can I do on Windows? Any advice on how to catch this?
UPDATE: I can press any key in my cmd.exe to unfreeze the program.
UPDATE:
It looks like it freezes on one of my debug-printfs:
STACK_TEXT:
: ntdll!NtWriteFile+0x14
: KERNELBASE!WriteFile+0x76
!write_text_ansi_nolock+0x183
!_write_nolock+0x451
!_write_internal+0x377
!__acrt_stdio_flush_nolock+0xc4
!__acrt_stdio_end_temporary_buffering_nolock+0x54
!__acrt_stdio_temporary_buffering_guard::~__acrt_stdio_temporary_buffering_guard+0x28
!<lambda_303760bc4008a2b3ec4768a30b06a80c>::operator()+0x104
!__crt_seh_guarded_call<int>::operator()<<lambda_d854c62834386a3b23916ad6dae2782d>,<lambda_303760bc4008a2b3ec4768a30b06a80c> &,<lambda_4780a7ea4f8cbd2590aec34bd14e2bbf> >+0x35
!__acrt_lock_stream_and_call<<lambda_303760bc4008a2b3ec4768a30b06a80c> >+0x58
!common_vfprintf<__crt_stdio_output::standard_base,char>+0x21a
!__stdio_common_vfprintf+0x5c
!_vfprintf_l+0x3f
!printf+0x58
! MyClass::myfunc -- that executes my handler of the button pressed (which freezes)
Why can be so? I mean it's just a printf writing to cmd.
Here is the answer to my question:
https://stackoverflow.com/a/33883532/4781940
I really have that Select Command Prompt title when the freeze happens.
I'm trying to install Elementary OS in VirtualBox, but the minimum resolution of the OS is 1024x768 and VirtualBox always boots in a much lower resolution. I can't install Guest Additions until the OS has been fully installed and I am on the desktop. I can't go through with the installation, though, because I only see about 60% of the screen in the top left corner. I've tried increasing video resolution to 128mb, but as I thought, that didn't work. Is there a way to increase the resolution with Guest Additions or something else before booting the system to install it?
I had an issue with the installation of Elementary OS 6 with VirtualBox for the same reason. The right side and bottom portion of the installer screens were cutoff. That area of the screen has buttons for back, submit, cancel.
I resolved this by making to selection to erase/complete install, then using the tab key twice followed by the enter key. Apparently this sequence of keystrokes allowed me to initiate the full installation script successfully.
same issue here,
end up add boot kernel parameter to fix this,
when first boot prompt(5 secs),
hit any key within the 5 secs count down to show boot options,
hit TAB to edit first option,
add the vga=ask to the end of boot kernel lines.
then it will show another 30 secs count down for VGA mode selection,
hit ENTER to choose proper one, in my case I choose 1280x800x32.
that's all,
more detail regarding boot vga parameters can refer to this URL.
https://linuxhint.com/set_screen_resolution_linux_kernel_boot/
The question
Is there a method to prevent an X session from starting the screensaver, going into power save mode, or performing a screen blank from code?
What I'm working with
Language: C/C++
GUI framework: GTK3
Hardware: Raspberry Pi 3B
Software: Raspbian 10 - Buster
My program needs to run on screen for long periods (up to 12 hours) with the GUI running without user interaction. The GUI acts as a status monitor for systems in field (if the screen goes black, something went wrong).
What I know
GTK3 can determine if the screensaver is active
GTK3 has a boolean property to report if the screensaver of the system is active (see here), but no other references are made in the documentation.
Raspbian uses screen blanking
Raspbian does not come installed with xscreensaver or other package to control the screen off time. Instead, it relies mostly on X to "blank screen". This can be managed with the xset command as a superuser. The canonical way to do this is reported in the hardware-specific Stack Exchange (here).
End-users cannot be trusted
In my case, the program will be used by folks who are barely computer literate. The result must be user-friendly and not expect the user to ever touch a terminal, let alone to make permanent changes to the startup config of X. While one option would be to distribute the program as a customized Raspbian disk image, I would like to explore other options.
I need to see an example
While there were some places to start using this question, implementing them is problematic. When I attempt to use the following MWE with and without the commented line, nothing happens. I cannot simulate the screen blanking function.
#include <X11/extensions/scrnsaver.h>
int main() {
// XScreenSaverSuspend;
XForceScreenSaver;
usleep(1000000);
return 0;
}
You have to pass parameters to the function:
void XScreenSaverSuspend(Display *dpy, Bool suspend);
#include <X11/extensions/scrnsaver.h>
int main() {
XScreenSaverSuspend (display, True);
usleep(1000000);
return 0;
}
But I don't think you have time to see the result with this program and when program ends the screensaver goes back to its previous state.
For your GTK framework, you can obtain the Display use:
Display *
gdk_x11_display_get_xdisplay (GdkDisplay *display);
Docs here.
For X:
/* use the information from the environment variable DISPLAY
to create the X connection:
*/
Display * dis = XOpenDisplay((char *)0); // or ":0.0"
A hacky, OS-specific solution:
Raspbian does not appear to require super user elevation to modify the xset. Adding the line to the code:
system("xset -dpms");
system("xset s off");
is sufficient to turn off the power management settings and the screensaver.
This is obviously sloppy, and it potentially leaves the OS in an undesirable state if the program breaks before these have a chance to be reset to default values. More elegant answers are encouraged.
When switching the TUI mode on and off (with Ctrl+x, a), gdb often gets stuck using only half the screen (so the cmd and src windows take only 1/4 of the screen each) and winheight cmd + 5 won't work.
How can I prevent or fix this?
This is apparently a problem related to readline.
Someone apparently already looked into it: http://patchwork.sourceware.org/patch/6398/ so hopefully it should be fixed in newer versions of gdb.
In the meantime, the following kludge can be used to fix the problem when it happens:
Toggle the TUI mode until you get the problem
Open another terminal on the computer where gdb is running and send SIGWINCH to the gdb process with a command like pkill -SIGWINCH gdb
Toggle the TUI mode a couple of times and gdb should pick up on the "new" height.
I had similar issue when I was working on Windows, connecting through Putty to my server where gdb was running.
I found out that gdb took from Putty information about terminal resolution (or putty delivered it to gdb?). Unfortunately, when Putty window was maximised, the information send/received described normal (restored) window size.
To solve it I just restored putty window to normal size, manually resized it to look as maximised and maximised once again. After switching TUI off and on I could work with whole the screen.
Everyone's raved about how awesome Qt is and I would really love to use it. However, after downloading it and trying to build a little Hello World app, the performance of the Qt Creator slogged to the point of being unusable.
The main problem is when I switch from "Edit" (code-view) to "Design" (form-view), it takes roughly 30-45 seconds for the form to draw every single time I do this. Here is a video of this happening.
Hitting CTRL-R to run my application takes 30-45 seconds to display my application.
If anyone has had these issues, please post a suggestion! I would really love to use Qt.
UPDATE: After closing Qt Creator, I notice that Hg Workbench (Mercurial) takes between 1-2 minutes to open (where it's regularly instant).
I'd suggest you to run the application i.e., qtcreator from a command prompt. Since qDebug will be printing out crucial information about the actions going on, you might have a chance to understand what exactly is causing the slowdown.
Just in case., try the new QtCreator2.5.1 which runs well. Even if this doesn't work, probably there should be something wrong with the OS. Check for any programs that are running in the background which can be choking on the processor.