User Tools

Site Tools


k15:k15.1:k15.1.3:start

15.1.3 Property ScreenSaver - Class Desktop (gb. desktop)

Behind the property Screensaver is the class _Desktop_ScreenSaver (gb.desktop). The class enables you to manage the power management and screen saver of the monitor. This virtual class has one Enabled property and 5 methods (Activate, Lock, Reset, Resume and Suspend).

  • The effect of the Suspend (Window AS Window) procedure is to override the screen saver function and the power management of the monitor. As a condition: The specified window must exist for the duration of the suspension/interruption.
  • The screen saver can be suspended simultaneously with multiple windows. In this case, the screensaver operation is restored only once.

By calling the Resume (Window AS Window) method, the screen saver function and the power management of the monitor are reactivated after they have been exposed. The window passed as a parameter must be the same as it was when you called the Suspend method (Window AS Window) before.

After calling Desktop.ScreenSaver.Suspend(FMain.Window) in a project source code, this message appears in the IDE console:

lockfile: Forcing lock on "/tmp/xdg-screensaver-hans--0.0.lock"

with the contents of the lock file /tmp/xdg-screensaver-hans–0.0:

52428803:7751

In one project, both the enabled property and the 5 methods (Activate, Lock, Reset, Resume and Suspend) were used to test their effect.

B1

Figure 15.1.3.1: 'ScreenSaver' project

This is followed by the complete source code, the most important passages of which are commented:

[1] ' Gambas class file
[2] 
[3] Public Sub Form_Open()
[4]   Dim bFlag As Boolean
[5]   
[6]   FMain.Center
[7]   FMain.Resizable = False
[8]   Desktop.ScreenSaver.Suspend(FMain.Window)
[9] 
[10]   ' bFlag = Desktop.ScreenSaver.Enabled
[11]   ' If bFlag = True Then
[12]   '    Message.Info("Desktop screen saver switched on.")
[13]   ' Else
[14]   '    Message.Info("Desktop screen saver switched off.")
[15]   ' Endif ' If bFlag = True ?
[16]   
[17] End ' Form_Open()
[18] 
[19] Public Sub btnDSSActivate_Click()
[20]   Desktop.ScreenSaver.Activate()  
[21] End ' btnDSSActivate_Click()  
[22] 
[23] Public Sub btnDSSLock_Click()
[24]   Desktop.ScreenSaver.Lock()
[25] End ' btnDSSLock_Click()
[26] 
[27] Public Sub btnDSSTest_Click()
[28]   Desktop.ScreenSaver.Resume(FMain.Window)
[29]   Desktop.ScreenSaver.Activate()
[30]   timerDSSWait.Delay = 1000 * 3
[31]   timerDSSWait.Start
[32] End ' btnDSSTest_Click()
[33] 
[34] Public Sub timerDSSWait_Timer()
[35]   Desktop.ScreenSaver.Reset()
[36]   Desktop.ScreenSaver.Suspend(FMain.Window)
[37]   timerDSSWait.Stop
[38] End ' timerWait_Timer()
[39] 
[40] Public Sub btnEnde_Click()
[41]   Desktop.ScreenSaver.Resume(FMain.Window)
[42]   Wait 0.05
[43]   FMain.Close
[44] End ' btnEnde_Click()
[45] 
[46] Public Sub Form_Close()
[47]    btnEnde_Click()
[48] End ' Form_Close()

Comment:

  • The lines 10-15 were commented out because of an error message: _Desktop_ScreenSaver.Enabled is static.
  • By calling the method in line 20, the screen saver is switched on immediately. A lockout depends on the system settings. Each activity turns off the screensaver immediately.
  • The method in line 24 blocks the screen immediately. The user password is required for unlocking.
  • In lines 27 to 38, the screen is switched on for a defined period of time. The lockout time of 3 seconds specified here is set via a timer.
  • In the procedure in lines 40-48 without a 'Wait 0.05' there was an error in the IDE-console (xdg-screensaver: Window 52428803 does not exist), because the form may not be closed before the screensaver was reactivated! Look - the short waiting time of 0.05 seconds seems to help.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k15/k15.1/k15.1.3/start.txt · Last modified: 28.09.2023 by emma

Page Tools