Back to index

bamf  0.2.120
Functions
bamf-xutils.c File Reference
#include "bamf-xutils.h"
#include <string.h>

Go to the source code of this file.

Functions

static Display * get_xdisplay (gboolean *opened)
char * bamf_xutils_get_window_hint (Window xid, const char *atom_name, Atom type)
void bamf_xutils_set_window_hint (Window xid, const char *atom_name, Atom type, const char *data)
void bamf_xutils_get_window_class_hints (Window xid, char **class_instance_name, char **class_name)

Function Documentation

void bamf_xutils_get_window_class_hints ( Window  xid,
char **  class_instance_name,
char **  class_name 
)

Definition at line 134 of file bamf-xutils.c.

{
  Display *xdisplay;
  gboolean close_display = FALSE;

  xdisplay = get_xdisplay (&close_display);

  if (!xdisplay)
  {
    g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
    return;
  }

  XClassHint class_hint;
  class_hint.res_name = NULL;
  class_hint.res_class = NULL;

  XGetClassHint(xdisplay, xid, &class_hint);

  if (class_name && class_hint.res_class && class_hint.res_class[0] != 0)
    *class_name = g_convert (class_hint.res_class, -1, "utf-8", "iso-8859-1",
                             NULL, NULL, NULL);

  if (class_instance_name && class_hint.res_name && class_hint.res_name[0] != 0)
    *class_instance_name = g_convert (class_hint.res_name, -1, "utf-8", "iso-8859-1",
                                      NULL, NULL, NULL);

  XFree (class_hint.res_class);
  XFree (class_hint.res_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* bamf_xutils_get_window_hint ( Window  xid,
const char *  atom_name,
Atom  type 
)

Definition at line 48 of file bamf-xutils.c.

{
  Display *XDisplay;
  Atom atom;
  char *hint = NULL;
  Atom result_type;
  gint format;
  gulong numItems;
  gulong bytesAfter;
  unsigned char *buffer;
  gboolean close_display = FALSE;

  g_return_val_if_fail ((xid != 0), NULL);
  g_return_val_if_fail (atom_name, NULL);

  XDisplay = get_xdisplay (&close_display);

  if (!XDisplay)
  {
    g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
    return NULL;
  }

  atom = XInternAtom (XDisplay, atom_name, FALSE);

  int result = XGetWindowProperty (XDisplay,
                                   xid,
                                   atom,
                                   0,
                                   G_MAXINT,
                                   FALSE,
                                   type,
                                   &result_type,
                                   &format,
                                   &numItems,
                                   &bytesAfter,
                                   &buffer);

  if (close_display)
    XCloseDisplay (XDisplay);

  if (result == Success && numItems > 0)
    {
      if (buffer && buffer[0] != '\0')
        hint = g_strdup ((char*) buffer);

      XFree (buffer);
    }

  return hint;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bamf_xutils_set_window_hint ( Window  xid,
const char *  atom_name,
Atom  type,
const char *  data 
)

Definition at line 101 of file bamf-xutils.c.

{
  Display *XDisplay;
  gboolean close_display = FALSE;

  g_return_if_fail (xid != 0);
  g_return_if_fail (atom_name);
  g_return_if_fail (data);
  
  XDisplay = get_xdisplay (&close_display);

  if (!XDisplay)
  {
    g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
    return;
  }

  XChangeProperty (XDisplay,
                   xid,
                   XInternAtom (XDisplay,
                   atom_name,
                   FALSE),
                   type,
                   8,
                   PropModeReplace,
                   (unsigned char *) data,
                   strlen (data));

  if (close_display)
    XCloseDisplay (XDisplay);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Display* get_xdisplay ( gboolean *  opened) [static]

Definition at line 25 of file bamf-xutils.c.

{
  Display *xdisplay;
  xdisplay = gdk_x11_get_default_xdisplay ();

  if (opened)
    *opened = FALSE;

  if (!xdisplay)
    {
      xdisplay = XOpenDisplay (NULL);

      if (xdisplay)
        {
          if (opened)
            *opened = TRUE;
        }
    }

  return xdisplay;
}

Here is the caller graph for this function: