@@ -6,8 +6,8 @@ const Cinnamon = imports.gi.Cinnamon;
66
77const XdgAppState = {
88 BACKGROUND : 0 , // window.is_hidden
9- RUNNING : 1 , // window visible
10- ACTIVE : 2 // window focused
9+ RUNNING : 1 , // window visible
10+ ACTIVE : 2 // window focused
1111}
1212
1313const CinnamonPortalIface =
@@ -26,7 +26,7 @@ var CinnamonPortalHandler = class CinnamonPortalHandler {
2626 this . _dbusImpl = Gio . DBusExportedObject . wrapJSObject ( CinnamonPortalIface , this ) ;
2727 this . _dbusImpl . export ( Gio . DBus . session , '/org/Cinnamon' ) ;
2828
29- this . running_apps = { }
29+ this . running_apps = { } ;
3030 Cinnamon . AppSystem . get_default ( ) . connect ( "app-state-changed" , ( ) => this . EmitRunningAppsChanged ( ) ) ;
3131 Cinnamon . WindowTracker . get_default ( ) . connect ( "notify::focus-app" , ( ) => this . EmitRunningAppsChanged ( ) ) ;
3232 }
@@ -37,18 +37,10 @@ var CinnamonPortalHandler = class CinnamonPortalHandler {
3737
3838 has_focus ( app ) {
3939 const fwin = global . display . get_focus_window ( ) ;
40- if ( fwin == null ) {
40+ if ( ! fwin ) {
4141 return false ;
4242 }
43-
44- const app_windows = app . get_windows ( ) ;
45- for ( let w of app_windows ) {
46- if ( w == fwin ) {
47- return true ;
48- }
49- }
50-
51- return false ;
43+ return app . get_windows ( ) . includes ( fwin ) ;
5244 }
5345
5446 /* org.freedesktop.impl.portal.Background.GetAppState:
@@ -66,21 +58,18 @@ var CinnamonPortalHandler = class CinnamonPortalHandler {
6658 if ( app . get_is_flatpak ( ) ) {
6759 id = app . get_flatpak_app_id ( ) ;
6860 }
69- else
70- {
61+ else {
7162 id = app . get_id ( ) ;
7263 }
64+ let state ;
7365 if ( app . get_n_windows ( ) === 0 ) {
74- apps [ id ] = GLib . Variant . new_uint32 ( XdgAppState . BACKGROUND ) ; // Can't happen currently.
66+ state = XdgAppState . BACKGROUND ;
67+ } else if ( this . has_focus ( app ) ) {
68+ state = XdgAppState . ACTIVE ;
7569 } else {
76- if ( this . has_focus ( app ) ) {
77- apps [ id ] = GLib . Variant . new_uint32 ( XdgAppState . ACTIVE ) ;
78- }
79- else
80- {
81- apps [ id ] = GLib . Variant . new_uint32 ( XdgAppState . RUNNING ) ;
82- }
70+ state = XdgAppState . RUNNING ;
8371 }
72+ apps [ id ] = GLib . Variant . new_uint32 ( state ) ;
8473 }
8574
8675 return new GLib . Variant ( "(a{sv})" , [ apps ] ) ;
0 commit comments