Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
xfactory.c File Reference
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <Xm/MwmUtil.h>
#include "guiIM.h"
#include "xfactory.h"

Go to the source code of this file.

Classes

struct  _PropWMState

Defines

#define PROP_WM_STATE_ELEMENTS   2

Typedefs

typedef struct _PropWMState PropWMState

Functions

static Bool GetWMState (Display *display, Window window)
static void getAtoms (Display *display)
static void remove_decoration (Display *display, Window window, int decoration)
void XFactoryRemoveDecoration (Display *display, Window window)
void XFactoryRemoveDecorationExceptTitle (Display *display, Window window)
void XFactoryRemoveAllDecoration (Display *display, Window window)
void XFactoryRemoveMenu (Display *display, Window window)
void XFactoryRemoveBorder (Display *display, Window window)
Window XFactoryGetFrameWindow (Display *display, Window window)
Window XFactoryGetToplevelWindow (Display *display, Window window)
void XFactoryGetLocationOnScreen (Display *display, Window window, int x, int y, XPoint *point)
Window XFactoryCreateIMWindow (Display *display, Window parent, Window transient_win, int x, int y, unsigned int width, unsigned int height, unsigned long bg, long event_mask, XIMFilter filters, int count)
void XFactoryAdjustPlacementInsideScreen (Display *dpy, Window win, int x, int y, int width, int height, int *ret_x, int *ret_y)
int XFactoryResizeWindowInsideScreen (Display *display, Window w, unsigned int width, unsigned int height)
int XFactoryMoveResizeWindowInsideScreen (Display *display, Window w, int x, int y, unsigned int width, unsigned int height)
int XFactoryMoveWindowInsideScreen (Display *display, Window w, int x, int y)
int XFactoryValidateCoordinates (Display *display, Window w, int *x, int *y)
Bool XFactoryCheckIMWindow (Display *display, Window window)
XFontSet XFactoryCreateDefaultFontSet (Display *display, char *default_fontname)
void XFactoryFreeDefaultFontSet (Display *display)

Variables

static Atom mwm_del_atom = (Atom)0
static Atom ol_del_atom = (Atom)0
static Atom ol_del_atom_list [3]
static int ol_atom_inx = 0
static XFontSet default_fontset = (XFontSet)0
static int ref_count = 0

Class Documentation

struct _PropWMState

Definition at line 284 of file Xfactory.cpp.

Class Members
unsigned long ion
unsigned long state

Define Documentation

#define PROP_WM_STATE_ELEMENTS   2

Definition at line 50 of file xfactory.c.


Typedef Documentation

typedef struct _PropWMState PropWMState

Function Documentation

static void getAtoms ( Display *  display) [static]

Definition at line 98 of file xfactory.c.

                                       {
    if (!mwm_del_atom) {
       mwm_del_atom = XInternAtom(display, "_MOTIF_WM_HINTS", True);
    }
    if (!ol_del_atom) {
        ol_atom_inx = 0;
       ol_del_atom = XInternAtom(display, "_OL_DECOR_DEL", True);
       ol_del_atom_list[ol_atom_inx++] =
           XInternAtom(display, "_OL_DECOR_RESIZE", True);
       ol_del_atom_list[ol_atom_inx++] =
           XInternAtom(display, "_OL_DECOR_HEADER", True);
    }
}

Here is the caller graph for this function:

static Bool GetWMState ( Display *  display,
Window  window 
) [static]

Definition at line 59 of file xfactory.c.

                                            {
    int ret_val;
    PropWMState *property = NULL;
    Atom actual_type;
    int actual_format;
    unsigned long nitems;
    unsigned long leftover;
    Atom wm_state = XInternAtom(display, "WM_STATE", True);

    ret_val = XGetWindowProperty(display, window, wm_state,
                             0L, PROP_WM_STATE_ELEMENTS,
                             False, wm_state,
                             &actual_type, &actual_format,
                             &nitems, &leftover,
                             (unsigned char **)&property);
    if (!((ret_val == Success) && (actual_type == wm_state) &&
         (nitems == PROP_WM_STATE_ELEMENTS))) {
       /*
        * The property could not be retrieved or is not correctly set up.
        */
       if (property) {
           XFree((char *)property);
       }
       return False;
    }
    if (property) {
       XFree((char *)property);
    }
    return True;
}

Here is the caller graph for this function:

static void remove_decoration ( Display *  display,
Window  window,
int  decoration 
) [static]

Definition at line 113 of file xfactory.c.

{
    struct _mwmhints {
       unsigned long flags, func, deco;
       long    input_mode;
       unsigned long status;
    } mwm_del_hints;
    
    getAtoms(display);

    if (mwm_del_atom != None) {
       mwm_del_hints.flags = 1L << 1; /* flags for decoration */
       mwm_del_hints.deco = decoration;
       XChangeProperty(display, window,
                     mwm_del_atom, mwm_del_atom, 32,
                     PropModeReplace,
                     (unsigned char *)&mwm_del_hints, 5);
    }
    if (ol_del_atom != None) {
        XChangeProperty(display, window, ol_del_atom, XA_ATOM, 32,
                     PropModeReplace, (unsigned char*)ol_del_atom_list,
                     ol_atom_inx);
    }

    {
      /* 4344419 */
      /* window title is attached while using enlightenment on linux */
      /* need to disable [x] (dismiss window) function */
      Atom wm_window_protocols[1];
      Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
      wm_window_protocols[0] = wm_delete_window;
      XSetWMProtocols(display, window, wm_window_protocols, 1);
    }
    {
      /* 4390729 */
      /* window should not grab any input focus */
      XWMHints wm_hints;
      wm_hints.flags = InputHint;
      wm_hints.input = False;
      XSetWMHints(display, window, &wm_hints);
    }
    {
      Atom net_wm_state = XInternAtom(display, "_NET_WM_STATE", False);
      Atom net_wm_state_skip_taskbar = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR", False);
      Atom net_wm_state_prop[1];

      net_wm_state_prop[0] = net_wm_state_skip_taskbar;
      XChangeProperty(display, window, net_wm_state, XA_ATOM, 32,
                    PropModeReplace, (unsigned char *) net_wm_state_prop, 1);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XFactoryAdjustPlacementInsideScreen ( Display *  dpy,
Window  win,
int  x,
int  y,
int  width,
int  height,
int *  ret_x,
int *  ret_y 
)

Definition at line 317 of file xfactory.c.

                                                          {
  XWindowAttributes attr;
  int dpy_width;
  int dpy_height;
  int screen_num;

  width += 20;
  height += 20;

  if (XGetWindowAttributes(dpy, win, &attr) > 0) {
    screen_num = XScreenNumberOfScreen(attr.screen);
  } else {
    screen_num = 0;
  }

  dpy_width = DisplayWidth(dpy, screen_num);
  dpy_height = DisplayHeight(dpy, screen_num);

  if (dpy_width < (x + width)) {
    if (width <= dpy_width) {
      *ret_x = (dpy_width - width);
    } else {
      *ret_x = 0;
    }
  } else {
    *ret_x = x;
  }

  if (dpy_height < (y + height)) {
    if (height <= dpy_height) {
      *ret_y = (dpy_height - height);
    } else {
      *ret_y = 0;
    }
  } else {
    *ret_y = y;
  }
}

Here is the caller graph for this function:

Bool XFactoryCheckIMWindow ( Display *  display,
Window  window 
)

Definition at line 426 of file xfactory.c.

                                                       {
  Window root;
  int ax, ay;
  unsigned int awidth, aheight, aborder, adepth;
  int s;

  if (!window) return False;

  s = XGetGeometry(display, window, &root, &ax, &ay,
                &awidth, &aheight, &aborder, &adepth);

  return s;
}

Here is the caller graph for this function:

XFontSet XFactoryCreateDefaultFontSet ( Display *  display,
char *  default_fontname 
)

Definition at line 444 of file xfactory.c.

{
  char **missing_list;
  int missing_count;
  char *def_string;
  char *base_font_name;

  ref_count++;

  if (default_fontset)
    return default_fontset;

  if (default_fontname && default_fontname[0])
    {
      base_font_name = default_fontname;
      default_fontset = XCreateFontSet (display,
                                   base_font_name, &missing_list,
                                   &missing_count, &def_string);
    }
  if (default_fontset)
    return default_fontset;

  base_font_name = DEFAULT_FONT_NAME_CDE;
  default_fontset = XCreateFontSet (display,
                                base_font_name, &missing_list,
                                &missing_count, &def_string);
  if (default_fontset)
    return default_fontset;

  base_font_name = DEFAULT_FONT_NAME;
  default_fontset = XCreateFontSet (display,
                                base_font_name, &missing_list,
                                &missing_count, &def_string);
  return default_fontset;
}

Here is the caller graph for this function:

Window XFactoryCreateIMWindow ( Display *  display,
Window  parent,
Window  transient_win,
int  x,
int  y,
unsigned int  width,
unsigned int  height,
unsigned long  bg,
long  event_mask,
XIMFilter  filters,
int  count 
)

Definition at line 279 of file xfactory.c.

                                                   {
  Window win;
  int i;
  Window top_win;

  if (width <= 0) width = 1;
  if (height <= 0) height = 1;

  win = XCreateSimpleWindow(display, parent,
                         x, y, width, height,
                         0, /* border width: who cares? */
                         0, /* border color */
                         bg);
  if (!win) return 0;

  XFactoryRemoveDecoration(display, win);

  /* query toplevel window */
  top_win = XFactoryGetToplevelWindow(display, transient_win);
  XSetTransientForHint(display, win, top_win);

  XSelectInput(display, win, event_mask);

  for (i = 0; i < count; i++) {
    _XRegisterFilterByType(display, win,
                        filters[i].type, filters[i].type,
                        filters[i].filter,
                        (XPointer)filters[i].client_data);
  }
  return win;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XFactoryFreeDefaultFontSet ( Display *  display)

Definition at line 481 of file xfactory.c.

{
  if (--ref_count == 0)
    {
      if (default_fontset)
       XFreeFontSet (display, default_fontset);
      default_fontset = 0;
    }
  return;
}

Here is the caller graph for this function:

Window XFactoryGetFrameWindow ( Display *  display,
Window  window 
)

Definition at line 209 of file xfactory.c.

                                                        {
    Window top_win;
    Window current_window = window;

    for (;;) {
        Window root_return, parent_return, *child_return = NULL;
        unsigned int nchild_return;
        top_win = current_window;
        if (XQueryTree(display, current_window,
                       &root_return, &parent_return,
                       &child_return, &nchild_return) == 0) {
            if (child_return) XFree(child_return);
            break;
        }
        if (child_return) XFree(child_return);
        current_window = parent_return;
        if (parent_return == root_return) break;
    }
    return top_win;
}

Here is the caller graph for this function:

void XFactoryGetLocationOnScreen ( Display *  display,
Window  window,
int  x,
int  y,
XPoint *  point 
)

Definition at line 259 of file xfactory.c.

                                                      {
  XWindowAttributes attr;
  Window child;
  int new_x, new_y;

  if (XGetWindowAttributes(display, window, &attr) > 0) {
    XTranslateCoordinates(display, window,
                       RootWindow(display,
                                 XScreenNumberOfScreen(attr.screen)),
                       x, y,
                       &new_x, &new_y, &child);

    point->x = new_x;
    point->y = new_y;
  }
  return;
}

Here is the caller graph for this function:

Window XFactoryGetToplevelWindow ( Display *  display,
Window  window 
)

Definition at line 231 of file xfactory.c.

                                                           {
    Window root_return, parent_return, *child_return = NULL, current_window;
    unsigned int nchild_return;

    if (GetWMState(display, window)) return window;

    current_window = window;
    for (;;) {
       if (XQueryTree(display, current_window,
                     &root_return, &parent_return,
                     &child_return, &nchild_return) == 0) {
           if (child_return) XFree(child_return);
           break;
       }
       if (child_return) XFree(child_return);
       if (GetWMState(display, parent_return)) {
           return parent_return;
       }
       if (parent_return == root_return) {
           return current_window;
       }
       current_window = parent_return;
    }
    /* error */
    return window;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int XFactoryMoveResizeWindowInsideScreen ( Display *  display,
Window  w,
int  x,
int  y,
unsigned int  width,
unsigned int  height 
)

Definition at line 379 of file xfactory.c.

                                                                          {
  XFactoryAdjustPlacementInsideScreen(display, w, x, y,
                                  width, height, &x, &y);
  XMoveResizeWindow(display, w, x, y, width, height);

  return 0;
}

Here is the call graph for this function:

int XFactoryMoveWindowInsideScreen ( Display *  display,
Window  w,
int  x,
int  y 
)

Definition at line 390 of file xfactory.c.

                                          {
  XWindowAttributes attr;

  if (XGetWindowAttributes(display, w, &attr) > 0) {
    XFactoryAdjustPlacementInsideScreen(display, w, x, y,
                                   attr.width, attr.height,
                                   &x, &y);
    XMoveWindow(display, w, x, y);
  }

  return 0;
}

Here is the call graph for this function:

void XFactoryRemoveAllDecoration ( Display *  display,
Window  window 
)

Definition at line 189 of file xfactory.c.

                                                             {
  remove_decoration(display, window, 0); /* set nothing */
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XFactoryRemoveBorder ( Display *  display,
Window  window 
)

Definition at line 201 of file xfactory.c.

                                                      {
  /* set all the flags other than border */
  remove_decoration(display, window,
                  1L << 2 | 1L << 3 | 1L << 4 | 1L << 5 | 1L << 6);
  return;
}

Here is the call graph for this function:

void XFactoryRemoveDecoration ( Display *  display,
Window  window 
)

Definition at line 177 of file xfactory.c.

                                                          {
  remove_decoration(display, window, 1L << 1); /* set Border only */
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XFactoryRemoveDecorationExceptTitle ( Display *  display,
Window  window 
)

Definition at line 183 of file xfactory.c.

                                                                     {
  remove_decoration(display, window, 1L << 1 | 1L << 3); /* set Border only */
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XFactoryRemoveMenu ( Display *  display,
Window  window 
)

Definition at line 195 of file xfactory.c.

                                                    {
  remove_decoration(display, window, 1L << 1 | 1L << 3);
  return;
}

Here is the call graph for this function:

int XFactoryResizeWindowInsideScreen ( Display *  display,
Window  w,
unsigned int  width,
unsigned int  height 
)

Definition at line 360 of file xfactory.c.

                                                                      {
  XWindowAttributes attr;
  int x;
  int y;

  if (XGetWindowAttributes(display, w, &attr) > 0) {
    XFactoryAdjustPlacementInsideScreen(display, w, attr.x, attr.y,
                                   width, height, &x, &y);
    if ((attr.x == x) && (attr.y == y)) {
      XResizeWindow(display, w, width, height);
    } else {
      XMoveResizeWindow(display, w, x, y, width, height);
    }
  }
  return 0;
}

Here is the call graph for this function:

int XFactoryValidateCoordinates ( Display *  display,
Window  w,
int *  x,
int *  y 
)

Definition at line 405 of file xfactory.c.

                                               {
  XWindowAttributes attr;
  int newx, newy;
  if (XGetWindowAttributes(display, w, &attr) > 0) {
    XFactoryAdjustPlacementInsideScreen(display, w, *x, *y,
                                        attr.width, attr.height,
                                        &newx, &newy);
    *x = newx;
    *y = newy;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

XFontSet default_fontset = (XFontSet)0 [static]

Definition at line 440 of file xfactory.c.

Atom mwm_del_atom = (Atom)0 [static]

Definition at line 91 of file xfactory.c.

int ol_atom_inx = 0 [static]

Definition at line 96 of file xfactory.c.

Atom ol_del_atom = (Atom)0 [static]

Definition at line 94 of file xfactory.c.

Atom ol_del_atom_list[3] [static]

Definition at line 95 of file xfactory.c.

int ref_count = 0 [static]

Definition at line 441 of file xfactory.c.