[mutter] display: Set xattr on focus window cgroup dir



commit 7555688d8d9582edc27213a543a9fe6919a599c3
Author: Nishal Kulkarni <nishalkulkarni gmail com>
Date:   Fri Aug 6 00:30:22 2021 +0530

    display: Set xattr on focus window cgroup dir
    
    Added a function `meta_window_set_inactive_since` it sets
    xattr on the cgroup directory for the given MetaWindow.
    
    Resource management daemons can then monitor these changes on xattr
    and make allocation decisions accordingly.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1960>

 src/core/display.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/src/core/display.c b/src/core/display.c
index 5d4a4da217..fcfc13fe4f 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1404,17 +1404,41 @@ meta_display_sync_wayland_input_focus (MetaDisplay *display)
 #endif
 }
 
+static void
+meta_window_set_inactive_since (MetaWindow  *window,
+                                int64_t      inactive_since_us)
+{
+  GFile *file = NULL;
+  g_autoptr (GFileInfo) file_info = NULL;
+  g_autofree char *timestamp = NULL;
+
+  timestamp = g_strdup_printf ("%" G_GINT64_FORMAT, inactive_since_us);
+
+  file = meta_window_get_unit_cgroup (window);
+  if (!file)
+    return;
+
+  file_info = g_file_info_new ();
+  g_file_info_set_attribute_string (file_info,
+                                    "xattr::xdg.inactive-since", timestamp);
+
+  if (!g_file_set_attributes_from_info (file, file_info,
+                                        G_FILE_QUERY_INFO_NONE,
+                                        NULL, NULL))
+    return;
+}
+
 void
 meta_display_update_focus_window (MetaDisplay *display,
                                   MetaWindow  *window)
 {
+  MetaWindow *previous = NULL;
+
   if (display->focus_window == window)
     return;
 
   if (display->focus_window)
     {
-      MetaWindow *previous;
-
       meta_topic (META_DEBUG_FOCUS,
                   "%s is now the previous focus window due to being focused out or unmapped",
                   display->focus_window->desc);
@@ -1440,6 +1464,15 @@ meta_display_update_focus_window (MetaDisplay *display,
   else
     meta_topic (META_DEBUG_FOCUS, "* Focus --> NULL");
 
+  if (!previous || !display->focus_window ||
+      !meta_window_unit_cgroup_equal (previous, display->focus_window))
+    {
+      if (previous)
+        meta_window_set_inactive_since (previous, g_get_monotonic_time ());
+      if (display->focus_window)
+        meta_window_set_inactive_since (display->focus_window, -1);
+    }
+
   if (meta_is_wayland_compositor ())
     meta_display_sync_wayland_input_focus (display);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]