LCOV - code coverage report
Current view: top level - src/plugins/xdp - valent-xdp-utils.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 0.0 % 22 0
Test Date: 2024-04-23 06:02:46 Functions: 0.0 % 4 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-xdp-utils"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <libportal/portal.h>
       9                 :             : #ifdef HAVE_LIBPORTAL_GTK4
      10                 :             : # include <gtk/gtk.h>
      11                 :             : # include <libportal-gtk4/portal-gtk4.h>
      12                 :             : #endif /* HAVE_LIBPORTAL_GTK4 */
      13                 :             : 
      14                 :             : #include "valent-xdp-utils.h"
      15                 :             : 
      16                 :             : 
      17                 :             : static XdpPortal *default_portal = NULL;
      18                 :             : 
      19                 :             : 
      20                 :             : #ifdef HAVE_LIBPORTAL_GTK4
      21                 :             : static GtkWindow *
      22                 :           0 : valent_xdp_get_active_window (void)
      23                 :             : {
      24                 :           0 :   GListModel *windows = NULL;
      25                 :           0 :   unsigned int n_windows = 0;
      26                 :             : 
      27                 :           0 :   windows = gtk_window_get_toplevels ();
      28                 :           0 :   n_windows = g_list_model_get_n_items (windows);
      29                 :             : 
      30                 :           0 :   for (unsigned int i = 0; i < n_windows; i++)
      31                 :             :     {
      32                 :           0 :       g_autoptr (GtkWindow) window = g_list_model_get_item (windows, i);
      33                 :             : 
      34                 :           0 :       if (gtk_window_is_active (window))
      35                 :             :         return g_steal_pointer (&window);
      36                 :             :     }
      37                 :             : 
      38                 :             :   return NULL;
      39                 :             : }
      40                 :             : #endif /* HAVE_LIBPORTAL_GTK4 */
      41                 :             : 
      42                 :             : /**
      43                 :             :  * valent_xdp_get_default:
      44                 :             :  *
      45                 :             :  * Get the default [class@Xdp.Portal] object for Valent.
      46                 :             :  *
      47                 :             :  * Returns: (transfer none): a `XdpPortal`
      48                 :             :  */
      49                 :             : XdpPortal *
      50                 :           0 : valent_xdp_get_default (void)
      51                 :             : {
      52                 :           0 :   if (default_portal == NULL)
      53                 :           0 :     default_portal = xdp_portal_new ();
      54                 :             : 
      55                 :           0 :   return default_portal;
      56                 :             : }
      57                 :             : 
      58                 :             : /**
      59                 :             :  * valent_xdp_get_parent:
      60                 :             :  *
      61                 :             :  * Get an [class@Xdp.Parent], if available.
      62                 :             :  *
      63                 :             :  * If Valent was compiled without support for libportal-gtk4 or there is no
      64                 :             :  * active window, this function will return %NULL.
      65                 :             :  *
      66                 :             :  * Returns: (nullable) (transfer full): a `XdpParent`
      67                 :             :  */
      68                 :             : XdpParent *
      69                 :           0 : valent_xdp_get_parent (void)
      70                 :             : {
      71                 :             : #ifdef HAVE_LIBPORTAL_GTK4
      72                 :           0 :   g_autoptr (GtkWindow) window = NULL;
      73                 :             : 
      74                 :           0 :   window = valent_xdp_get_active_window ();
      75                 :             : 
      76                 :           0 :   if (window != NULL)
      77                 :           0 :     return xdp_parent_new_gtk (window);
      78                 :             : #endif /* HAVE_LIBPORTAL_GTK4 */
      79                 :             : 
      80                 :             :   return NULL;
      81                 :             : }
      82                 :             : 
      83                 :             : /**
      84                 :             :  * valent_xdp_has_parent:
      85                 :             :  *
      86                 :             :  * Check if an active parent is available.
      87                 :             :  *
      88                 :             :  * If Valent was compiled without support for libportal-gtk4 or there is no
      89                 :             :  * active window, this function will return %FALSE.
      90                 :             :  *
      91                 :             :  * Returns: %TRUE if there is an active window, or %FALSE if not
      92                 :             :  */
      93                 :             : gboolean
      94                 :           0 : valent_xdp_has_parent (void)
      95                 :             : {
      96                 :             : #ifdef HAVE_LIBPORTAL_GTK4
      97                 :           0 :   g_autoptr (GtkWindow) window = NULL;
      98                 :             : 
      99                 :           0 :   window = valent_xdp_get_active_window ();
     100                 :             : 
     101                 :           0 :   if (window != NULL)
     102                 :           0 :     return TRUE;
     103                 :             : #endif /* HAVE_LIBPORTAL_GTK4 */
     104                 :             : 
     105                 :             :   return FALSE;
     106                 :             : }
     107                 :             : 
        

Generated by: LCOV version 2.0-1