Back to index

bamf  0.2.120
Classes | Defines | Typedefs | Functions
bamf-matcher.h File Reference
#include "bamf.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <libgtop-2.0/glibtop.h>
#include <glibtop/procargs.h>
#include <glibtop/procuid.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _BamfMatcherClass
struct  _BamfMatcher

Defines

#define BAMF_TYPE_MATCHER   (bamf_matcher_get_type ())
#define BAMF_MATCHER(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_MATCHER, BamfMatcher))
#define BAMF_IS_MATCHER(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_MATCHER))
#define BAMF_MATCHER_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_MATCHER, BamfMatcherClass))
#define BAMF_IS_MATCHER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_MATCHER))
#define BAMF_MATCHER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_MATCHER, BamfMatcherClass))
#define _NET_WM_DESKTOP_FILE   "_NET_WM_DESKTOP_FILE"
#define WM_WINDOW_ROLE   "WM_WINDOW_ROLE"

Typedefs

typedef struct _BamfMatcher
typedef struct _BamfMatcherClass
typedef struct _BamfMatcherPrivate

Functions

GType bamf_matcher_get_type (void) G_GNUC_CONST
void bamf_matcher_load_desktop_file (BamfMatcher *self, const char *desktop_file)
void bamf_matcher_register_desktop_file_for_pid (BamfMatcher *self, const char *application, gint pid)
const char * bamf_matcher_get_desktop_file_class (BamfMatcher *self, const char *desktop_file)
const char * bamf_matcher_get_active_application (BamfMatcher *matcher)
 bamf_matcher_get_active_application: : a #BamfMatcher
const char * bamf_matcher_get_active_window (BamfMatcher *matcher)
 bamf_matcher_get_active_window: : a #BamfMatcher
const char * bamf_matcher_application_for_xid (BamfMatcher *matcher, guint32 xid)
gboolean bamf_matcher_application_is_running (BamfMatcher *matcher, const char *application)
GVariant * bamf_matcher_application_dbus_paths (BamfMatcher *matcher)
GVariant * bamf_matcher_window_dbus_paths (BamfMatcher *matcher)
const char * bamf_matcher_dbus_path_for_application (BamfMatcher *matcher, const char *application)
void bamf_matcher_register_favorites (BamfMatcher *matcher, const char **favorites)
GList * bamf_matcher_get_favorites (BamfMatcher *matcher)
GVariant * bamf_matcher_running_application_paths (BamfMatcher *matcher)
GVariant * bamf_matcher_tab_dbus_paths (BamfMatcher *matcher)
GVariant * bamf_matcher_xids_for_application (BamfMatcher *matcher, const char *application)
GVariant * bamf_matcher_get_window_stack_for_monitor (BamfMatcher *matcher, gint monitor)
 bamf_matcher_get_window_stack_for_monitor: : a #BamfMatcher : the monitor you want the stack from, negative value to get all
BamfMatcher * bamf_matcher_get_default (void)
 bamf_matcher_get_default: : a #BamfMatcher

Class Documentation

struct _BamfMatcher

Definition at line 57 of file bamf-matcher.h.

Class Members
GObject parent
BamfDBusMatcherSkeleton parent
BamfMatcherPrivate * priv

Define Documentation

#define _NET_WM_DESKTOP_FILE   "_NET_WM_DESKTOP_FILE"

Definition at line 48 of file bamf-matcher.h.

#define BAMF_IS_MATCHER (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_MATCHER))

Definition at line 43 of file bamf-matcher.h.

#define BAMF_IS_MATCHER_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_MATCHER))

Definition at line 45 of file bamf-matcher.h.

#define BAMF_MATCHER (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_MATCHER, BamfMatcher))

Definition at line 42 of file bamf-matcher.h.

#define BAMF_MATCHER_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_MATCHER, BamfMatcherClass))

Definition at line 44 of file bamf-matcher.h.

#define BAMF_MATCHER_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_MATCHER, BamfMatcherClass))

Definition at line 46 of file bamf-matcher.h.

Definition at line 41 of file bamf-matcher.h.

#define WM_WINDOW_ROLE   "WM_WINDOW_ROLE"

Definition at line 49 of file bamf-matcher.h.


Typedef Documentation

typedef struct _BamfMatcher

Definition at line 51 of file bamf-matcher.h.

typedef struct _BamfMatcherClass

Definition at line 52 of file bamf-matcher.h.

typedef struct _BamfMatcherPrivate

Definition at line 53 of file bamf-matcher.h.


Function Documentation

GVariant* bamf_matcher_application_dbus_paths ( BamfMatcher *  matcher)

Definition at line 2527 of file bamf-matcher.c.

{
  GList *l;
  BamfView *view;
  BamfMatcherPrivate *priv;
  GVariantBuilder b;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
  g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));

  priv = matcher->priv;

  for (l = priv->views; l; l = l->next)
    {
      view = l->data;

      if (!BAMF_IS_APPLICATION (view))
        continue;

      g_variant_builder_add (&b, "s", bamf_view_get_path (view));
    }

  g_variant_builder_close (&b);

  return g_variant_builder_end (&b);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* bamf_matcher_application_for_xid ( BamfMatcher *  matcher,
guint32  xid 
)

Definition at line 2396 of file bamf-matcher.c.

{
  GList *l;
  BamfView *view;
  BamfMatcherPrivate *priv;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  priv = matcher->priv;

  for (l = priv->views; l; l = l->next)
    {
      view = l->data;

      if (!BAMF_IS_APPLICATION (view))
        continue;

      if (bamf_application_manages_xid (BAMF_APPLICATION (view), xid))
        {
          return bamf_view_get_path (view);
        }
    }

  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean bamf_matcher_application_is_running ( BamfMatcher *  matcher,
const char *  application 
)

Definition at line 2479 of file bamf-matcher.c.

{
  BamfApplication *app;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE);

  app = bamf_matcher_get_application_by_desktop_file (matcher, application);

  if (BAMF_IS_APPLICATION (app))
    {
      return bamf_view_is_running (BAMF_VIEW (app));
    }

  return FALSE;
}

Here is the call graph for this function:

const char* bamf_matcher_dbus_path_for_application ( BamfMatcher *  matcher,
const char *  application 
)

Definition at line 2557 of file bamf-matcher.c.

{
  const char * path = "";
  BamfApplication *app;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  app = bamf_matcher_get_application_by_desktop_file (matcher, application);

  if (BAMF_IS_APPLICATION (app))
    {
      return bamf_view_get_path (BAMF_VIEW (app));
    }

  return path;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* bamf_matcher_get_active_application ( BamfMatcher *  matcher)

bamf_matcher_get_active_application: : a #BamfMatcher

Used to fetch the active #BamfApplication.

Returns: (transfer none): The active #BamfApplication.

Definition at line 359 of file bamf-matcher.c.

{
  BamfMatcherPrivate *priv;
  BamfView *view;
  char *app = NULL;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
  priv = matcher->priv;

  if (!dbus_g_proxy_call (priv->proxy,
                          "ActiveApplication",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_STRING, &app,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch path: %s", error->message);
      g_error_free (error);
      return NULL;
    }

  if (app && app[0] == '\0')
    {
      g_free (app);
      return NULL;
    }

  if (!app)
    return NULL;

  BamfFactory *factory = _bamf_factory_get_default ();
  view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
  g_free (app);

  if (!BAMF_IS_APPLICATION (view))
    return NULL;

  return BAMF_APPLICATION (view);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* bamf_matcher_get_active_window ( BamfMatcher *  matcher)

bamf_matcher_get_active_window: : a #BamfMatcher

Used to fetch the active #BamfWindow.

Returns: (transfer none): The active #BamfWindow.

Definition at line 401 of file bamf-matcher.c.

{
  BamfMatcherPrivate *priv;
  BamfView *view;
  char *win = NULL;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
  priv = matcher->priv;

  if (!dbus_g_proxy_call (priv->proxy,
                          "ActiveWindow",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_STRING, &win,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch path: %s", error->message);
      g_error_free (error);
      return NULL;
    }

  if (win && win[0] == '\0')
    {
      g_free (win);
      return NULL;
    }

  if (!win)
    return NULL;

  BamfFactory *factory = _bamf_factory_get_default ();
  view = _bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW);
  g_free (win);

  if (!BAMF_IS_WINDOW (view))
    return NULL;

  return BAMF_WINDOW (view);
}

Here is the call graph for this function:

Here is the caller graph for this function:

BamfMatcher* bamf_matcher_get_default ( void  )

bamf_matcher_get_default: : a #BamfMatcher

Returns the default matcher. This matcher is owned by bamf and shared between other callers.

Returns: (transfer none): A new #BamfMatcher

Definition at line 350 of file bamf-matcher.c.

{
  if (BAMF_IS_MATCHER (default_matcher))
    return g_object_ref (default_matcher);

  return (default_matcher = g_object_new (BAMF_TYPE_MATCHER, NULL));
}

Here is the caller graph for this function:

const char* bamf_matcher_get_desktop_file_class ( BamfMatcher *  self,
const char *  desktop_file 
)

Definition at line 2323 of file bamf-matcher.c.

{
  g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
  g_return_val_if_fail (desktop_file, NULL);

  return g_hash_table_lookup (self->priv->desktop_class_table, desktop_file);
}

Here is the caller graph for this function:

GList* bamf_matcher_get_favorites ( BamfMatcher *  matcher)

Definition at line 2576 of file bamf-matcher.c.

{
  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
  
  return matcher->priv->favorites;
}

Here is the caller graph for this function:

GType bamf_matcher_get_type ( void  )
GVariant* bamf_matcher_get_window_stack_for_monitor ( BamfMatcher *  matcher,
gint  monitor 
)

bamf_matcher_get_window_stack_for_monitor: : a #BamfMatcher : the monitor you want the stack from, negative value to get all

Used to fetch all windows that BAMF knows about in the requested screen, in stacking bottom-to-top order.

Returns: (element-type Bamf.View) (transfer container): A list of #BamfWindow.

Definition at line 612 of file bamf-matcher.c.

{
  BamfMatcherPrivate *priv;
  BamfView *view;
  char **array = NULL;
  int i, len;
  GList *result = NULL;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
  priv = matcher->priv;

  if (!dbus_g_proxy_call (priv->proxy,
                          "WindowStackForMonitor",
                          &error,
                          G_TYPE_INT,
                          monitor,
                          G_TYPE_INVALID,
                          G_TYPE_STRV, &array,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch paths: %s", error->message);
      g_error_free (error);
      
      return NULL;
    }

  if (!array)
    return NULL;

  BamfFactory *factory = _bamf_factory_get_default ();
  len = g_strv_length (array);
  for (i = len-1; i >= 0; i--)
    {
      view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_WINDOW);

      if (BAMF_IS_WINDOW (view))
        result = g_list_prepend (result, view);
    }
  
  g_strfreev (array);
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bamf_matcher_load_desktop_file ( BamfMatcher *  self,
const char *  desktop_file 
)

Definition at line 2247 of file bamf-matcher.c.

{
  GList *vl, *wl;

  g_return_if_fail (BAMF_IS_MATCHER (self));

  load_desktop_file_to_table (self,
                              desktop_file,
                              self->priv->desktop_file_table,
                              self->priv->desktop_id_table,
                              self->priv->desktop_class_table);

  /* If an application with no .desktop file has windows that matches
   * the new added .desktop file, then we try to re-match them. */
  for (vl = self->priv->views; vl; vl = vl->next)
    {
      if (!BAMF_IS_APPLICATION (vl->data))
        continue;

      BamfApplication *app = BAMF_APPLICATION (vl->data);

      if (!bamf_application_get_desktop_file (app))
        {
          GList *children = bamf_view_get_children (BAMF_VIEW (app));

          for (wl = children; wl; wl = wl->next)
          {
            if (!BAMF_IS_WINDOW (wl->data))
              continue;

            BamfWindow *win = BAMF_WINDOW (wl->data);
            GList *desktops = bamf_matcher_possible_applications_for_window (self, win, NULL);

            if (g_list_find_custom (desktops, desktop_file, (GCompareFunc) g_strcmp0))
              {
                BamfLegacyWindow *legacy_window = bamf_window_get_window (win);
                bamf_legacy_window_reopen (legacy_window);
              }
          }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bamf_matcher_register_desktop_file_for_pid ( BamfMatcher *  self,
const char *  application,
gint  pid 
)

Definition at line 2292 of file bamf-matcher.c.

{
  gpointer key;
  BamfLegacyScreen *screen;
  GList *glist_item;
  GList *windows;

  g_return_if_fail (BAMF_IS_MATCHER (self));
  g_return_if_fail (desktopFile);

  key = GINT_TO_POINTER (pid);
  g_hash_table_insert (self->priv->registered_pids, key, g_strdup (desktopFile));

  /* fixme, this is a bit heavy */

  screen = bamf_legacy_screen_get_default ();

  g_return_if_fail (BAMF_IS_LEGACY_SCREEN (screen));

  windows = bamf_legacy_screen_get_windows (screen);

  for (glist_item = windows; glist_item != NULL;
       glist_item = glist_item->next)
    {
      ensure_window_hint_set (self, glist_item->data);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bamf_matcher_register_favorites ( BamfMatcher *  matcher,
const char **  favorites 
)

Definition at line 2584 of file bamf-matcher.c.

{
  const char *fav;
  const char **favs;
  BamfMatcherPrivate *priv;

  g_return_if_fail (BAMF_IS_MATCHER (matcher));
  g_return_if_fail (favorites);
  priv = matcher->priv;
  
  for (favs = favorites; *favs; favs++)
    {
      fav = *favs;
      /* ignore things already in the list */
      if (g_list_find_custom (priv->favorites, fav, (GCompareFunc) g_strcmp0))
        continue;

      bamf_matcher_load_desktop_file (matcher, fav);
      priv->favorites = g_list_prepend (priv->favorites, g_strdup (fav));
    }

  g_signal_emit (matcher, matcher_signals[FAVORITES_CHANGED], 0);
}

Here is the call graph for this function:

GVariant* bamf_matcher_running_application_paths ( BamfMatcher *  matcher)

Definition at line 2610 of file bamf-matcher.c.

{
  GList *l;
  BamfView *view;
  BamfMatcherPrivate *priv;
  GVariantBuilder b;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
  g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));

  priv = matcher->priv;

  for (l = priv->views; l; l = l->next)
    {
      view = l->data;

      if (!BAMF_IS_APPLICATION (view) || !bamf_view_is_running (view))
        continue;

      g_variant_builder_add (&b, "s", bamf_view_get_path (view));
    }

  g_variant_builder_close (&b);

  return g_variant_builder_end (&b);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant* bamf_matcher_tab_dbus_paths ( BamfMatcher *  matcher)

Definition at line 2693 of file bamf-matcher.c.

{
  GVariantBuilder b;

  g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
  g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
  g_variant_builder_close (&b);
  return g_variant_builder_end (&b);
}

Here is the caller graph for this function:

GVariant* bamf_matcher_window_dbus_paths ( BamfMatcher *  matcher)

Definition at line 2497 of file bamf-matcher.c.

{
  GList *l;
  BamfView *view;
  BamfMatcherPrivate *priv;
  GVariantBuilder b;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
  g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));

  priv = matcher->priv;

  for (l = priv->views; l; l = l->next)
    {
      view = l->data;

      if (!BAMF_IS_WINDOW (view))
        continue;

      g_variant_builder_add (&b, "s", bamf_view_get_path (view));
    }

  g_variant_builder_close (&b);

  return g_variant_builder_end (&b);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant* bamf_matcher_xids_for_application ( BamfMatcher *  matcher,
const char *  application 
)

Definition at line 2704 of file bamf-matcher.c.

{
  GVariantBuilder b;
  GVariant *xids;
  BamfApplication *app;

  g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);

  xids = NULL;
  app = bamf_matcher_get_application_by_desktop_file (matcher, application);

  if (BAMF_IS_APPLICATION (app))
    {
      xids = bamf_application_get_xids (app);
    }

  if (!xids)
    {
      g_variant_builder_init (&b, G_VARIANT_TYPE ("(au)"));
      g_variant_builder_open (&b, G_VARIANT_TYPE ("au"));
      g_variant_builder_close (&b);
      xids = g_variant_builder_end (&b);
    }

  return xids;
}

Here is the call graph for this function:

Here is the caller graph for this function: