Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michel Le Bihan
gajim
Commits
e145689e
Verified
Commit
e145689e
authored
1 year ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Idle: Make attributes private
parent
25500014
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gajim/common/idle.py
+49
-48
49 additions, 48 deletions
gajim/common/idle.py
with
49 additions
and
48 deletions
gajim/common/idle.py
+
49
−
48
View file @
e145689e
...
...
@@ -59,10 +59,10 @@ class DBusFreedesktop(IdleMonitor):
def
__init__
(
self
)
->
None
:
IdleMonitor
.
__init__
(
self
)
self
.
last_idle_time
=
0
self
.
_
last_idle_time
=
0
log
.
debug
(
'
Connecting to org.freedesktop.ScreenSaver
'
)
self
.
dbus_proxy
=
Gio
.
DBusProxy
.
new_for_bus_sync
(
self
.
_
dbus_proxy
=
Gio
.
DBusProxy
.
new_for_bus_sync
(
Gio
.
BusType
.
SESSION
,
Gio
.
DBusProxyFlags
.
NONE
,
None
,
...
...
@@ -80,7 +80,7 @@ class DBusFreedesktop(IdleMonitor):
log
.
debug
(
'
Test successful
'
)
def
_get_idle_sec_fail
(
self
)
->
int
:
(
idle_time
,)
=
cast
(
tuple
[
int
],
self
.
dbus_proxy
.
call_sync
(
(
idle_time
,)
=
cast
(
tuple
[
int
],
self
.
_
dbus_proxy
.
call_sync
(
'
GetSessionIdleTime
'
,
None
,
Gio
.
DBusCallFlags
.
NO_AUTO_START
,
...
...
@@ -91,23 +91,23 @@ class DBusFreedesktop(IdleMonitor):
def
get_idle_sec
(
self
)
->
int
:
try
:
self
.
last_idle_time
=
self
.
_get_idle_sec_fail
()
self
.
_
last_idle_time
=
self
.
_get_idle_sec_fail
()
except
GLib
.
Error
as
error
:
log
.
warning
(
'
org.freedesktop.ScreenSaver.GetSessionIdleTime() failed: %s
'
,
error
)
return
self
.
last_idle_time
return
self
.
_
last_idle_time
class
DBusGnome
(
IdleMonitor
):
def
__init__
(
self
)
->
None
:
IdleMonitor
.
__init__
(
self
)
self
.
last_idle_time
=
0
self
.
_
last_idle_time
=
0
log
.
debug
(
'
Connecting to org.gnome.Mutter.IdleMonitor
'
)
self
.
dbus_
gnome_
proxy
=
Gio
.
DBusProxy
.
new_for_bus_sync
(
self
.
_
dbus_proxy
=
Gio
.
DBusProxy
.
new_for_bus_sync
(
Gio
.
BusType
.
SESSION
,
Gio
.
DBusProxyFlags
.
NONE
,
None
,
...
...
@@ -125,7 +125,7 @@ class DBusGnome(IdleMonitor):
log
.
debug
(
'
Test successful
'
)
def
_get_idle_sec_fail
(
self
)
->
int
:
(
idle_time
,)
=
cast
(
tuple
[
int
],
self
.
dbus_
gnome_
proxy
.
call_sync
(
(
idle_time
,)
=
cast
(
tuple
[
int
],
self
.
_
dbus_proxy
.
call_sync
(
'
GetIdletime
'
,
None
,
Gio
.
DBusCallFlags
.
NO_AUTO_START
,
...
...
@@ -136,13 +136,13 @@ class DBusGnome(IdleMonitor):
def
get_idle_sec
(
self
)
->
int
:
try
:
self
.
last_idle_time
=
self
.
_get_idle_sec_fail
()
self
.
_
last_idle_time
=
self
.
_get_idle_sec_fail
()
except
GLib
.
Error
as
error
:
log
.
warning
(
'
org.gnome.Mutter.IdleMonitor.GetIdletime() failed: %s
'
,
error
)
return
self
.
last_idle_time
return
self
.
_
last_idle_time
class
Xss
(
IdleMonitor
):
...
...
@@ -165,59 +165,60 @@ class Xss(IdleMonitor):
xid
=
ctypes
.
c_ulong
c_int_p
=
ctypes
.
POINTER
(
ctypes
.
c_int
)
lib
X
11path
=
ctypes
.
util
.
find_library
(
'
X11
'
)
if
lib
X
11path
is
None
:
lib
_x
11
_
path
=
ctypes
.
util
.
find_library
(
'
X11
'
)
if
lib
_x
11
_
path
is
None
:
raise
OSError
(
'
libX11 could not be found.
'
)
libX11
=
ctypes
.
cdll
.
LoadLibrary
(
libX11path
)
libX11
.
XOpenDisplay
.
restype
=
display_p
libX11
.
XOpenDisplay
.
argtypes
=
(
ctypes
.
c_char_p
,)
libX11
.
XDefaultRootWindow
.
restype
=
xid
libX11
.
XDefaultRootWindow
.
argtypes
=
(
display_p
,)
libXsspath
=
ctypes
.
util
.
find_library
(
'
Xss
'
)
if
libXsspath
is
None
:
lib_x11
=
ctypes
.
cdll
.
LoadLibrary
(
lib_x11_path
)
lib_x11
.
XOpenDisplay
.
restype
=
display_p
lib_x11
.
XOpenDisplay
.
argtypes
=
(
ctypes
.
c_char_p
,)
lib_x11
.
XDefaultRootWindow
.
restype
=
xid
lib_x11
.
XDefaultRootWindow
.
argtypes
=
(
display_p
,)
lib_xss_path
=
ctypes
.
util
.
find_library
(
'
Xss
'
)
if
lib_xss_path
is
None
:
raise
OSError
(
'
libXss could not be found.
'
)
self
.
libXss
=
ctypes
.
cdll
.
LoadLibrary
(
libXsspath
)
self
.
lib
Xss
.
XScreenSaverQueryExtension
.
argtypes
=
(
display_p
,
c_int_p
,
c_int_p
)
self
.
lib
X
ss
.
XScreenSaverAllocInfo
.
restype
=
XScreenSaverInfo_p
self
.
lib
X
ss
.
XScreenSaverQueryInfo
.
argtypes
=
(
self
.
_
lib
_xss
=
ctypes
.
cdll
.
LoadLibrary
(
lib_xss_path
)
self
.
_lib_xss
.
XScreenSaverQueryExtension
.
argtypes
=
(
display_p
,
c_int_p
,
c_int_p
)
self
.
_
lib
_x
ss
.
XScreenSaverAllocInfo
.
restype
=
XScreenSaverInfo_p
self
.
_
lib
_x
ss
.
XScreenSaverQueryInfo
.
argtypes
=
(
display_p
,
xid
,
XScreenSaverInfo_p
)
self
.
dpy_p
=
lib
X
11
.
XOpenDisplay
(
None
)
if
self
.
dpy_p
is
None
:
self
.
_
dpy_p
=
lib
_x
11
.
XOpenDisplay
(
None
)
if
self
.
_
dpy_p
is
None
:
raise
OSError
(
'
Could not open X Display.
'
)
_event_basep
=
ctypes
.
c_int
()
_error_basep
=
ctypes
.
c_int
()
extension
=
self
.
lib
X
ss
.
XScreenSaverQueryExtension
(
self
.
dpy_p
,
ctypes
.
byref
(
_event_basep
),
ctypes
.
byref
(
_error_basep
))
extension
=
self
.
_
lib
_x
ss
.
XScreenSaverQueryExtension
(
self
.
_
dpy_p
,
ctypes
.
byref
(
_event_basep
),
ctypes
.
byref
(
_error_basep
))
if
extension
==
0
:
raise
OSError
(
'
XScreenSaver Extension not available on display.
'
)
self
.
xss_info_p
=
self
.
lib
X
ss
.
XScreenSaverAllocInfo
()
if
self
.
xss_info_p
is
None
:
self
.
_
xss_info_p
=
self
.
_
lib
_x
ss
.
XScreenSaverAllocInfo
()
if
self
.
_
xss_info_p
is
None
:
raise
OSError
(
'
XScreenSaverAllocInfo: Out of Memory.
'
)
self
.
rootwindow
=
lib
X
11
.
XDefaultRootWindow
(
self
.
dpy_p
)
self
.
root
_
window
=
lib
_x
11
.
XDefaultRootWindow
(
self
.
_
dpy_p
)
def
get_idle_sec
(
self
)
->
int
:
info
=
self
.
lib
X
ss
.
XScreenSaverQueryInfo
(
self
.
dpy_p
,
self
.
rootwindow
,
self
.
xss_info_p
)
info
=
self
.
_
lib
_x
ss
.
XScreenSaverQueryInfo
(
self
.
_
dpy_p
,
self
.
root
_
window
,
self
.
_
xss_info_p
)
if
info
==
0
:
return
info
return
self
.
xss_info_p
.
contents
.
idle
//
1000
return
self
.
_
xss_info_p
.
contents
.
idle
//
1000
class
Windows
(
IdleMonitor
):
def
__init__
(
self
)
->
None
:
IdleMonitor
.
__init__
(
self
)
self
.
OpenInputDesktop
=
ctypes
.
windll
.
user32
.
OpenInputDesktop
self
.
CloseDesktop
=
ctypes
.
windll
.
user32
.
CloseDesktop
self
.
SystemParametersInfo
=
ctypes
.
windll
.
user32
.
SystemParametersInfoW
self
.
GetTickCount
=
ctypes
.
windll
.
kernel32
.
GetTickCount
self
.
GetLastInputInfo
=
ctypes
.
windll
.
user32
.
GetLastInputInfo
self
.
_
OpenInputDesktop
=
ctypes
.
windll
.
user32
.
OpenInputDesktop
self
.
_
CloseDesktop
=
ctypes
.
windll
.
user32
.
CloseDesktop
self
.
_
SystemParametersInfo
=
ctypes
.
windll
.
user32
.
SystemParametersInfoW
self
.
_
GetTickCount
=
ctypes
.
windll
.
kernel32
.
GetTickCount
self
.
_
GetLastInputInfo
=
ctypes
.
windll
.
user32
.
GetLastInputInfo
self
.
_locked_time
=
None
...
...
@@ -227,12 +228,12 @@ class Windows(IdleMonitor):
(
'
dwTime
'
,
ctypes
.
c_uint
)
]
self
.
lastInputInfo
=
LastInputInfo
()
self
.
lastInputInfo
.
cbSize
=
ctypes
.
sizeof
(
self
.
lastInputInfo
)
self
.
_
lastInputInfo
=
LastInputInfo
()
self
.
_
lastInputInfo
.
cbSize
=
ctypes
.
sizeof
(
self
.
_
lastInputInfo
)
def
get_idle_sec
(
self
)
->
int
:
self
.
GetLastInputInfo
(
ctypes
.
byref
(
self
.
lastInputInfo
))
return
int
(
self
.
GetTickCount
()
-
self
.
lastInputInfo
.
dwTime
)
//
1000
self
.
_
GetLastInputInfo
(
ctypes
.
byref
(
self
.
_
lastInputInfo
))
return
int
(
self
.
_
GetTickCount
()
-
self
.
_
lastInputInfo
.
dwTime
)
//
1000
def
set_extended_away
(
self
,
state
:
bool
)
->
None
:
raise
NotImplementedError
...
...
@@ -241,7 +242,7 @@ class Windows(IdleMonitor):
# Check if Screen Saver is running
# 0x72 is SPI_GETSCREENSAVERRUNNING
saver_runing
=
ctypes
.
c_int
(
0
)
info
=
self
.
SystemParametersInfo
(
info
=
self
.
_
SystemParametersInfo
(
0x72
,
0
,
ctypes
.
byref
(
saver_runing
),
0
)
if
info
and
saver_runing
.
value
:
return
True
...
...
@@ -249,9 +250,9 @@ class Windows(IdleMonitor):
# Check if Screen is locked
# Also a UAC prompt counts as locked
# So just return True if we are more than 10 seconds locked
desk
=
self
.
OpenInputDesktop
(
0
,
False
,
0
)
desk
=
self
.
_
OpenInputDesktop
(
0
,
False
,
0
)
unlocked
=
bool
(
desk
)
self
.
CloseDesktop
(
desk
)
self
.
_
CloseDesktop
(
desk
)
if
unlocked
:
self
.
_locked_time
=
None
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment