@@ -54,7 +54,7 @@ const ApplicationWindow = GObject.registerClass({
5454 #library
5555 #bookViewer
5656 #stack = new Gtk . Stack ( )
57- #cookie
57+ #inhibitCookie = null
5858 constructor ( params ) {
5959 super ( params )
6060 Object . assign ( this , {
@@ -82,16 +82,29 @@ const ApplicationWindow = GObject.registerClass({
8282 [ 'default-width' , 'default-height' , 'maximized' , 'fullscreened' ] )
8383
8484
85+ const app = Gio . Application . get_default ( )
86+ const inhibitIdle = ( win ) => {
87+ if ( this . #inhibitCookie) return
88+ const inhibitCookie = app . inhibit (
89+ win ,
90+ Gtk . ApplicationInhibitFlags . IDLE ,
91+ 'Reading book in fullscreen or a maximized window'
92+ )
93+ if ( inhibitCookie === 0 ) console . error ( 'Failed to inhibit session idle' )
94+ else this . #inhibitCookie = inhibitCookie
95+ }
96+ const uninhibitIdle = ( ) => {
97+ if ( ! this . #inhibitCookie) return
98+ app . uninhibit ( this . #inhibitCookie)
99+ this . #inhibitCookie = null
100+ }
85101 this . connect ( 'notify::fullscreened' , ( win ) => {
86- let app = Gio . Application . get_default ( )
87- if ( this . is_fullscreen ( ) ) {
88- this . #cookie = app . inhibit ( win , Gtk . ApplicationInhibitFlags . IDLE ,
89- 'Reading book in fullscreen' )
90- if ( this . #cookie == 0 )
91- console . error ( 'Failed to inhibit session idle' )
92- } else if ( this . #cookie > 0 ) {
93- app . uninhibit ( this . #cookie)
94- }
102+ if ( this . is_fullscreen ( ) || this . is_maximized ( ) ) inhibitIdle ( win )
103+ else uninhibitIdle ( )
104+ } )
105+ this . connect ( 'notify::maximized' , ( win ) => {
106+ if ( this . is_fullscreen ( ) || this . is_maximized ( ) ) inhibitIdle ( win )
107+ else uninhibitIdle ( )
95108 } )
96109
97110 if ( this . file ) this . openFile ( this . file )
0 commit comments