Back to index

bamf  0.2.120
Classes | Defines | Enumerations | Functions | Variables
bamf-window.c File Reference
#include "bamf-view-private.h"
#include "bamf-window.h"
#include "bamf-factory.h"
#include "bamf-marshal.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>

Go to the source code of this file.

Classes

struct  _BamfWindowPrivate

Defines

#define BAMF_WINDOW_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_WINDOW, BamfWindowPrivate))

Enumerations

enum  { MONITOR_CHANGED, MAXIMIZED_CHANGED, LAST_SIGNAL }

Functions

 G_DEFINE_TYPE (BamfWindow, bamf_window, BAMF_TYPE_VIEW)
 SECTION:bamf-window : The base class for all windows.
time_t bamf_window_last_active (BamfWindow *self)
BamfWindow * bamf_window_get_transient (BamfWindow *self)
BamfWindowType bamf_window_get_window_type (BamfWindow *self)
guint32 bamf_window_get_pid (BamfWindow *self)
guint32 bamf_window_get_xid (BamfWindow *self)
static void bamf_window_active_changed (BamfView *view, gboolean active)
static void bamf_window_on_monitor_changed (DBusGProxy *proxy, gint old, gint new, BamfWindow *self)
static void bamf_window_on_maximized_changed (DBusGProxy *proxy, gint old, gint new, BamfWindow *self)
static void bamf_window_unset_proxy (BamfWindow *self)
static void bamf_window_set_path (BamfView *view, const char *path)
gchar * bamf_window_get_utf8_prop (BamfWindow *self, const char *xprop)
gint bamf_window_get_monitor (BamfWindow *self)
BamfWindowMaximizationType bamf_window_maximized (BamfWindow *self)
static void bamf_window_dispose (GObject *object)
static void bamf_window_class_init (BamfWindowClass *klass)
static void bamf_window_init (BamfWindow *self)
BamfWindow * bamf_window_new (const char *path)

Variables

static guint window_signals [LAST_SIGNAL] = { 0 }

Class Documentation

struct _BamfWindowPrivate

Definition at line 50 of file bamf-window.c.

Class Members
gulong closed_id
DBusGConnection * connection
BamfDBusItemWindow * dbus_iface
gulong geometry_changed_id
time_t last_active
BamfLegacyWindow * legacy_window
BamfWindowMaximizationType maximized
gint monitor
gulong name_changed_id
time_t opened
guint32 pid
DBusGProxy * proxy
gulong state_changed_id
guint32 xid

Define Documentation

#define BAMF_WINDOW_GET_PRIVATE (   o)    (G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_WINDOW, BamfWindowPrivate))

Definition at line 47 of file bamf-window.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
MONITOR_CHANGED 
MAXIMIZED_CHANGED 
LAST_SIGNAL 

Definition at line 61 of file bamf-window.c.


Function Documentation

static void bamf_window_active_changed ( BamfView *  view,
gboolean  active 
) [static]

Definition at line 204 of file bamf-window.c.

{
  BamfWindow *self;

  g_return_if_fail (BAMF_IS_WINDOW (view));

  self = BAMF_WINDOW (view);
  
  if (active)
    self->priv->last_active = time (NULL);
}

Here is the caller graph for this function:

static void bamf_window_class_init ( BamfWindowClass *  klass) [static]

Definition at line 418 of file bamf-window.c.

{
  GObjectClass  *obj_class  = G_OBJECT_CLASS (klass);
  BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);

  g_type_class_add_private (obj_class, sizeof (BamfWindowPrivate));
  
  obj_class->dispose     = bamf_window_dispose;
  view_class->active_changed = bamf_window_active_changed;
  view_class->set_path   = bamf_window_set_path;
  
  window_signals[MONITOR_CHANGED] = 
    g_signal_new ("monitor-changed",
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (BamfWindowClass, monitor_changed),
                  NULL, NULL,
                  _bamf_marshal_VOID__INT_INT,
                  G_TYPE_NONE, 2,
                  G_TYPE_INT, G_TYPE_INT);

  window_signals[MAXIMIZED_CHANGED] = 
    g_signal_new ("maximized-changed",
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (BamfWindowClass, maximized_changed),
                  NULL, NULL,
                  _bamf_marshal_VOID__INT_INT,
                  G_TYPE_NONE, 2,
                  G_TYPE_INT, G_TYPE_INT);
}

Here is the call graph for this function:

static void bamf_window_dispose ( GObject *  object) [static]

Definition at line 406 of file bamf-window.c.

{
  BamfWindow *self;
  
  self = BAMF_WINDOW (object);
  bamf_window_unset_proxy (self);

  if (G_OBJECT_CLASS (bamf_window_parent_class)->dispose)
    G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint bamf_window_get_monitor ( BamfWindow *  self)

Definition at line 344 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  gint monitor = -2;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
  priv = self->priv;

  if (priv->monitor != -2 || !_bamf_view_remote_ready (BAMF_VIEW (self)))
    {
      return priv->monitor;
    }

  if (!dbus_g_proxy_call (priv->proxy,
                          "Monitor",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_INT, &monitor,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch monitor: %s", error->message);
      g_error_free (error);

      return -1;
    }

  return monitor;
}

Here is the caller graph for this function:

guint32 bamf_window_get_pid ( BamfWindow *  self)

Definition at line 143 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  guint32 pid = 0;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
  priv = self->priv;

  if (priv->pid != 0)
    return priv->pid;

  if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
    return 0;

  if (!dbus_g_proxy_call (priv->proxy,
                          "GetPid",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_UINT, &pid,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch pid: %s", error->message);
      g_error_free (error);
      return 0;
    }

  return pid;
}

Here is the caller graph for this function:

BamfWindow* bamf_window_get_transient ( BamfWindow *  self)

Definition at line 78 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  BamfView *transient;
  char *path = NULL;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
  priv = self->priv;

  if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
    return NULL;

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

  BamfFactory *factory = _bamf_factory_get_default ();
  transient = _bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
  g_free (path);  

  if (!BAMF_IS_WINDOW (transient))
    return NULL;
    
  return BAMF_WINDOW (transient);
}

Here is the caller graph for this function:

gchar* bamf_window_get_utf8_prop ( BamfWindow *  self,
const char *  xprop 
)

Definition at line 308 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  char *result = NULL;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
  priv = self->priv;

  if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
    return NULL;

  if (!dbus_g_proxy_call (priv->proxy,
                          "Xprop",
                          &error,
                          G_TYPE_STRING, xprop,
                          G_TYPE_INVALID,
                          G_TYPE_STRING, &result,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch property: %s", error->message);
      g_error_free (error);

      return NULL;
    }

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

  return result;
}

Here is the call graph for this function:

Definition at line 116 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  guint32 type = 0;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
  priv = self->priv;

  if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
    return 0;

  if (!dbus_g_proxy_call (priv->proxy,
                          "WindowType",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_UINT, &type,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch type: %s", error->message);
      g_error_free (error);
      return 0;
    }

  return (BamfWindowType) type;
}

Here is the caller graph for this function:

guint32 bamf_window_get_xid ( BamfWindow *  self)

Definition at line 173 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  guint32 xid = 0;
  GError *error = NULL;
  
  g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
  priv = self->priv;
  
  if (priv->xid != 0)
    return priv->xid;

  if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
    return 0;

  if (!dbus_g_proxy_call (priv->proxy,
                          "GetXid",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_UINT, &xid,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch xid: %s", error->message);
      g_error_free (error);
      return 0;
    }

  return xid;
}

Here is the caller graph for this function:

static void bamf_window_init ( BamfWindow *  self) [static]

Definition at line 451 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  GError           *error = NULL;

  priv = self->priv = BAMF_WINDOW_GET_PRIVATE (self);

  priv->xid = 0;
  priv->pid = 0;
  priv->monitor = -2;
  priv->maximized = -1;

  priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  if (priv->connection == NULL)
    {
      g_critical ("Failed to open connection to bus: %s",
               error != NULL ? error->message : "Unknown");
      if (error)
        g_error_free (error);
      return;
    }
}
time_t bamf_window_last_active ( BamfWindow *  self)

Definition at line 71 of file bamf-window.c.

{
  g_return_val_if_fail (BAMF_IS_WINDOW (self), (time_t) 0);
  
  return self->priv->last_active;
}

Definition at line 375 of file bamf-window.c.

{
  BamfWindowPrivate *priv;
  BamfWindowMaximizationType maximized = -1;
  GError *error = NULL;

  g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
  priv = self->priv;

  if (priv->maximized != -1 || !_bamf_view_remote_ready (BAMF_VIEW (self)))
    {
      return priv->maximized;
    }

  if (!dbus_g_proxy_call (priv->proxy,
                          "Maximized",
                          &error,
                          G_TYPE_INVALID,
                          G_TYPE_INT, &maximized,
                          G_TYPE_INVALID))
    {
      g_warning ("Failed to fetch maximized state: %s", error->message);
      g_error_free (error);

      return -1;
    }

  return maximized;
}

Here is the caller graph for this function:

BamfWindow* bamf_window_new ( const char *  path)

Definition at line 475 of file bamf-window.c.

{
  BamfWindow *self;
  self = g_object_new (BAMF_TYPE_WINDOW, NULL);

  _bamf_view_set_path (BAMF_VIEW (self), path);

  return self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void bamf_window_on_maximized_changed ( DBusGProxy *  proxy,
gint  old,
gint  new,
BamfWindow *  self 
) [static]

Definition at line 224 of file bamf-window.c.

{
  self->priv->maximized = new;
  g_signal_emit (G_OBJECT (self), window_signals[MAXIMIZED_CHANGED], 0, old, new);
}

Here is the caller graph for this function:

static void bamf_window_on_monitor_changed ( DBusGProxy *  proxy,
gint  old,
gint  new,
BamfWindow *  self 
) [static]

Definition at line 217 of file bamf-window.c.

{
  self->priv->monitor = new;
  g_signal_emit (G_OBJECT (self), window_signals[MONITOR_CHANGED], 0, old, new);
}

Here is the caller graph for this function:

static void bamf_window_set_path ( BamfView *  view,
const char *  path 
) [static]

Definition at line 256 of file bamf-window.c.

{
  BamfWindow *self;
  BamfWindowPrivate *priv;
  
  self = BAMF_WINDOW (view);
  priv = self->priv;

  bamf_window_unset_proxy (self);
  priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
                                           "org.ayatana.bamf",
                                           path,
                                           "org.ayatana.bamf.window");
  if (priv->proxy == NULL)
    {
      g_error ("Unable to get org.ayatana.bamf.window window");
      return;
    }

  priv->xid = bamf_window_get_xid (self);
  priv->monitor = bamf_window_get_monitor (self);
  priv->maximized = bamf_window_maximized (self);

  dbus_g_object_register_marshaller ((GClosureMarshal) _bamf_marshal_VOID__INT_INT,
                                     G_TYPE_NONE, 
                                     G_TYPE_INT, G_TYPE_INT,
                                     G_TYPE_INVALID);

  dbus_g_proxy_add_signal (priv->proxy,
                           "MonitorChanged",
                           G_TYPE_INT,
                           G_TYPE_INT,
                           G_TYPE_INVALID);

  dbus_g_proxy_connect_signal (priv->proxy,
                               "MonitorChanged",
                               (GCallback) bamf_window_on_monitor_changed,
                               self, NULL);

  dbus_g_proxy_add_signal (priv->proxy,
                           "MaximizedChanged",
                           G_TYPE_INT,
                           G_TYPE_INT,
                           G_TYPE_INVALID);

  dbus_g_proxy_connect_signal (priv->proxy,
                               "MaximizedChanged",
                               (GCallback) bamf_window_on_maximized_changed,
                               self, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void bamf_window_unset_proxy ( BamfWindow *  self) [static]

Definition at line 231 of file bamf-window.c.

{
  BamfWindowPrivate *priv;

  g_return_if_fail (BAMF_IS_WINDOW (self));
  priv = self->priv;

  if (!priv->proxy)
    return;

  dbus_g_proxy_disconnect_signal (self->priv->proxy,
                                  "MaximizedChanged",
                                  (GCallback) bamf_window_on_maximized_changed,
                                  self);

  dbus_g_proxy_disconnect_signal (self->priv->proxy,
                                  "MonitorChanged",
                                  (GCallback) bamf_window_on_monitor_changed,
                                  self);

  g_object_unref (priv->proxy);
  priv->proxy = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

G_DEFINE_TYPE ( BamfWindow  ,
bamf_window  ,
BAMF_TYPE_VIEW   
)

SECTION:bamf-window : The base class for all windows.

BamfWindow is the base class that all windows need to derive from.


Variable Documentation

guint window_signals[LAST_SIGNAL] = { 0 } [static]

Definition at line 69 of file bamf-window.c.