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).

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:

Download