Esempio n. 1
0
EAPI Ecore_X_Atom *
ecore_x_window_prop_list(Ecore_X_Window win,
                         int *num_ret)
{
   Ecore_X_Atom *atoms;
   Atom *atom_ret;
   int num = 0, i;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (num_ret)
     *num_ret = 0;

   atom_ret = XListProperties(_ecore_x_disp, win, &num);
   if (_ecore_xlib_sync) ecore_x_sync();
   if (!atom_ret)
     return NULL;

   atoms = malloc(num * sizeof(Ecore_X_Atom));
   if (atoms)
     {
        for (i = 0; i < num; i++)
          atoms[i] = atom_ret[i];
        if (num_ret)
          *num_ret = num;
     }

   XFree(atom_ret);
   return atoms;
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
	Display *dpy;
	Atom *atom;
	int i,natoms;

	/* connect to X server */
	if ((dpy=XOpenDisplay(NULL))==NULL) {
		fprintf(stderr,"Cannot connect to display %s\n",
			XDisplayName(NULL));
		exit(-1);
	}

	/* list properties of root window */
	atom = XListProperties(dpy,DefaultRootWindow(dpy),&natoms);
	printf("Number of properties = %d\n",natoms);
	for (i=0; i<natoms; i++)
		printf("property[%d] = %s\n",i,XGetAtomName(dpy,atom[i]));

	/* close connection to X server */
	XCloseDisplay(dpy);

	return EXIT_SUCCESS;
}
Esempio n. 3
0
Atom *
count_xlistproperties( const char *fname, int line, Display * display,
                       Window w, int *props_num )
{
    Atom *props ;

    props = XListProperties (display, w, props_num);
    if( props != NULL && *props_num > 0 )
        count_alloc (fname, line, (void *)props,
                     (*props_num)*sizeof(Atom), C_XMEM | C_XLISTPROPERTIES);
    return props;
}
Esempio n. 4
0
void list_props(void *buf, fuse_fill_dir_t filler, Window w)
{
    Atom *atoms;
    char *name;
    int count, i;

    filler(buf, "name", NULL, 0);
    filler(buf, "geometry", NULL, 0);
    atoms = XListProperties(dpy, w, &count);
    for (i = 0; i < count; i++) {
        name = XGetAtomName(dpy, atoms[i]);
        filler(buf, name, NULL, 0);
    }
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_hasProperty(JNIEnv *env, jclass unusued, jlong display, jlong window_ptr, jlong property_ptr) {
	Display *disp = (Display *)(intptr_t)display;
	Window window = (Window)window_ptr;
	Atom property = (Atom)property_ptr;
	int num_props;
	Atom *properties = XListProperties(disp, window, &num_props);
	if (properties == NULL)
		return JNI_FALSE;
	jboolean result = JNI_FALSE;
	for (int i = 0; i < num_props; i++) {
		if (properties[i] == property) {
			result = JNI_TRUE;
			break;
		}
	}
	XFree(properties);
	return result;
}
Esempio n. 6
0
bool window_has_property(Display* dpy, Window window, char* prop_name) {
    // find the properties this window has
    int num_properties_ret;
    Atom* properties= XListProperties(g_display, window, &num_properties_ret);

    bool atom_found = false;
    char* name;
    for(int i = 0; i < num_properties_ret; i++) {
        name = XGetAtomName(g_display, properties[i]);
        if(!strcmp(prop_name, name)) {
            atom_found = true;
            break;
        }
        XFree(name);
    }
    XFree(properties);

    return atom_found;
}
Esempio n. 7
0
static int
has_property(Display * display, Window window, Atom prop)
{
	int         nprops, j, retval = 0;
	Atom       *list = XListProperties(display, window, &nprops);

	if (err_occurred)
		return 0;

	for (j = 0; j < nprops; j++) {
		if (list[j] == prop) {
			retval = 1;
			break;
		}
	}

	if (nprops)
		XFree((caddr_t) list);

	return retval;
}
Esempio n. 8
0
/*
 * Return TRUE if window "w" exists and has a "Vim" property on it.
 */
static int isWindowValid(VimRemotingClient *client, Window w)
{
    XErrorHandler   old_handler;
    Atom *plist;
    int numProp;
    int i;
    int retval = FALSE;

    plist = XListProperties(client->dpy, w, &numProp);
    XSync(client->dpy, False);
    if (plist == NULL || client->got_x_error)
        return FALSE;

    for (i = 0; i < numProp; i++) {
        if (plist[i] == client->vimProperty) {
            retval = TRUE;
            break;
        }
    }
    XFree(plist);
    return retval;
}
Esempio n. 9
0
gboolean check_x11win_classhint( Window win ){
    //检查client window的属性,如果是未定义的窗口(多半是浏览器里的文本输入框),则返回FALSE
    Display* dpy;
    Atom* prop_list;
    int prop_count = 0;
    Window root;
    Window parent;
    Window* child_list;
    int child_count;

    gboolean return_flag = TRUE;

    //首先,不断查询当前window的parent,直到获取一个有prop,可以获得信息的window id
    g_debug("check_x11win_classhint start win id = %x", win);
    dpy = GDK_DISPLAY();
    XQueryTree( dpy, win, &root, &parent, &child_list, &child_count );
    XFree(child_list);
    g_debug("check_x11win_classhint query root = %x, parent = %x", root, parent );
    prop_list = XListProperties( dpy, win, &prop_count );
    g_debug("check_x11win_classhint get prop_count =  %d", prop_count );

    if ( ( root == parent ) && ( prop_count <= 0 ) ) {
        //输入窗口就是自己根窗口的变态,我也只想得出n900系统浏览器这一个了……
        //and all qt program orz...
        //so check prop_count <= 0
        g_debug("check_x11win_classhint find bt mircoB");
        XFree(prop_list);
        return_flag = FALSE;
        return return_flag;
    }

    while( prop_count == 0 && root != parent ){
        XFree(prop_list);
        win = parent;
        XQueryTree( dpy, win, &root, &parent, &child_list, &child_count );
        XFree(child_list);
        g_debug("check_x11win_classhint query root = %x, parent = %x", root, parent );
        prop_list = XListProperties( dpy, win, &prop_count );
        g_debug("check_x11win_classhint get prop_count =  %d", prop_count );
    }
    XFree(prop_list);

    //检查classhint
    XClassHint classhint;
    XGetClassHint( dpy, win, &classhint );
    if ( classhint.res_name == NULL && classhint.res_class == NULL ){
        g_debug( "check_x11win_classhint get undefined win" );
        return_flag = FALSE;
    }
    else
        g_debug( "check_x11win_classhint res_name = %s, res_class = %s", classhint.res_name, classhint.res_class );
    if ( g_strcmp0( classhint.res_class, "Firefox" ) == 0 ){
        g_debug("check_x11win_classhint find firefox");
        /*return_flag = FALSE;*/
        return_flag = TRUE;
    }
    XFree( classhint.res_name );
    XFree( classhint.res_class );

    g_debug("check_x11win_classhint end");

    return return_flag;
}
Esempio n. 10
0
bool
XWindowsClipboard::sendReply(Reply* reply)
{
	assert(reply != NULL);

	// bail out immediately if reply is done
	if (reply->m_done) {
		LOG((CLOG_DEBUG1 "clipboard: finished reply to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property));
		return true;
	}

	// start in failed state if property is None
	bool failed = (reply->m_property == None);
	if (!failed) {
		LOG((CLOG_DEBUG1 "clipboard: setting property on 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property));

		// send using INCR if already sending incrementally or if reply
		// is too large, otherwise just send it.
		const UInt32 maxRequestSize = 3 * XMaxRequestSize(m_display);
		const bool useINCR = (reply->m_data.size() > maxRequestSize);

		// send INCR reply if incremental and we haven't replied yet
		if (useINCR && !reply->m_replied) {
			UInt32 size = reply->m_data.size();
			if (!XWindowsUtil::setWindowProperty(m_display,
								reply->m_requestor, reply->m_property,
								&size, 4, m_atomINCR, 32)) {
				failed = true;
			}
		}

		// send more INCR reply or entire non-incremental reply
		else {
			// how much more data should we send?
			UInt32 size = reply->m_data.size() - reply->m_ptr;
			if (size > maxRequestSize)
				size = maxRequestSize;

			// send it
			if (!XWindowsUtil::setWindowProperty(m_display,
								reply->m_requestor, reply->m_property,
								reply->m_data.data() + reply->m_ptr,
								size,
								reply->m_type, reply->m_format)) {
				failed = true;
			}
			else {
				reply->m_ptr += size;

				// we've finished the reply if we just sent the zero
				// size incremental chunk or if we're not incremental.
				reply->m_done = (size == 0 || !useINCR);
			}
		}
	}

	// if we've failed then delete the property and say we're done.
	// if we haven't replied yet then we can send a failure notify,
	// otherwise we've failed in the middle of an incremental
	// transfer;  i don't know how to cancel that so i'll just send
	// the final zero-length property.
	// FIXME -- how do you gracefully cancel an incremental transfer?
	if (failed) {
		LOG((CLOG_DEBUG1 "clipboard: sending failure to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property));
		reply->m_done = true;
		if (reply->m_property != None) {
			XWindowsUtil::ErrorLock lock(m_display);
			XDeleteProperty(m_display, reply->m_requestor, reply->m_property);
		}

		if (!reply->m_replied) {
			sendNotify(reply->m_requestor, m_selection,
								reply->m_target, None,
								reply->m_time);

			// don't wait for any reply (because we're not expecting one)
			return true;
		}
		else {
			static const char dummy = 0;
			XWindowsUtil::setWindowProperty(m_display,
								reply->m_requestor, reply->m_property,
								&dummy,
								0,
								reply->m_type, reply->m_format);

			// wait for delete notify
			return false;
		}
	}

	// send notification if we haven't yet
	if (!reply->m_replied) {
		LOG((CLOG_DEBUG1 "clipboard: sending notify to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property));
		reply->m_replied = true;

		// dump every property on the requestor window to the debug2
		// log.  we've seen what appears to be a bug in lesstif and
		// knowing the properties may help design a workaround, if
		// it becomes necessary.
		if (CLOG->getFilter() >= kDEBUG2) {
			XWindowsUtil::ErrorLock lock(m_display);
			int n;
			Atom* props = XListProperties(m_display, reply->m_requestor, &n);
			LOG((CLOG_DEBUG2 "properties of 0x%08x:", reply->m_requestor));
			for (int i = 0; i < n; ++i) {
				Atom target;
				String data;
				char* name = XGetAtomName(m_display, props[i]);
				if (!XWindowsUtil::getWindowProperty(m_display,
								reply->m_requestor,
								props[i], &data, &target, NULL, False)) {
					LOG((CLOG_DEBUG2 "  %s: <can't read property>", name));
				}
				else {
					// if there are any non-ascii characters in string
					// then print the binary data.
					static const char* hex = "0123456789abcdef";
					for (String::size_type j = 0; j < data.size(); ++j) {
						if (data[j] < 32 || data[j] > 126) {
							String tmp;
							tmp.reserve(data.size() * 3);
							for (j = 0; j < data.size(); ++j) {
								unsigned char v = (unsigned char)data[j];
								tmp += hex[v >> 16];
								tmp += hex[v & 15];
								tmp += ' ';
							}
							data = tmp;
							break;
						}
					}
					char* type = XGetAtomName(m_display, target);
					LOG((CLOG_DEBUG2 "  %s (%s): %s", name, type, data.c_str()));
					if (type != NULL) {
						XFree(type);
					}
				}
				if (name != NULL) {
					XFree(name);
				}
			}
Esempio n. 11
0
File: testerrors.c Progetto: BYC/gtk
static void
test_error_trapping (GdkDisplay *gdk_display)
{
  Display *d;
  int dummy;
  int error;

  d = GDK_DISPLAY_XDISPLAY (gdk_display);

  /* verify that we can catch errors */
  gdk_error_trap_push ();
  XListProperties (d, 0, &dummy); /* round trip */
  error = gdk_error_trap_pop ();
  g_assert (error == BadWindow);

  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345); /* not a round trip */
  XSetCloseDownMode (d, DestroyAll);
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);

  /* try the same without sync */
  gdk_error_trap_push ();
  XListProperties (d, 0, &dummy);
  gdk_error_trap_pop_ignored ();

  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  XSetCloseDownMode (d, DestroyAll);
  gdk_error_trap_pop_ignored ();

  XSync (d, TRUE);

  /* verify that we can catch with nested traps; inner-most
   * active trap gets the error */
  gdk_error_trap_push ();
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);
  error = gdk_error_trap_pop ();
  g_assert (error == Success);

  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_push ();
  error = gdk_error_trap_pop ();
  g_assert (error == Success);
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);

  /* try nested, without sync */
  gdk_error_trap_push ();
  gdk_error_trap_push ();
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_pop_ignored ();
  gdk_error_trap_pop_ignored ();
  gdk_error_trap_pop_ignored ();

  XSync (d, TRUE);

  /* try nested, without sync, with interleaved calls */
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_pop_ignored ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_pop_ignored ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_pop_ignored ();

  XSync (d, TRUE);

  /* don't want to get errors that weren't in our push range */
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  gdk_error_trap_push ();
  XSync (d, TRUE); /* not an error */
  error = gdk_error_trap_pop ();
  g_assert (error == Success);
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);

  /* non-roundtrip non-error request after error request, inside trap */
  gdk_error_trap_push ();
  XSetCloseDownMode (d, 12345);
  XMapWindow (d, DefaultRootWindow (d));
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);

  /* a non-roundtrip non-error request before error request, inside trap */
  gdk_error_trap_push ();
  XMapWindow (d, DefaultRootWindow (d));
  XSetCloseDownMode (d, 12345);
  error = gdk_error_trap_pop ();
  g_assert (error == BadValue);

  /* Not part of any test, just a double-check
   * that all errors have arrived
   */
  XSync (d, TRUE);
}
Esempio n. 12
0
main()
{
      Window w2;

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Screen *scr = DefaultScreenOfDisplay(dpy);

      // CreateWindow

      Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			       CopyFromParent, CopyFromParent,
			       0, NIL);

      XDestroyWindow(dpy, w);

      // CreateWindow with arguments

      XSetWindowAttributes swa;
      swa.background_pixel = WhitePixelOfScreen(scr);
      swa.bit_gravity = NorthWestGravity;
      swa.border_pixel = BlackPixelOfScreen(scr);
      swa.colormap = DefaultColormapOfScreen(scr);
      swa.cursor = None;
      swa.win_gravity = NorthGravity;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, 
			&swa);
      
      // CreateWindow with other arguments

      XDestroyWindow(dpy, w);

      Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr));
      assert(pixmap);

      swa.background_pixmap = pixmap;
      swa.border_pixmap = pixmap;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixmap | CWBorderPixmap,
			&swa);
      
      // ChangeWindowAttributes

      swa.backing_planes = 0x1;
      swa.backing_pixel = WhitePixelOfScreen(scr);
      swa.save_under = True;
      swa.event_mask = KeyPressMask | KeyReleaseMask;
      swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask;
      swa.override_redirect = False;
      XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask
			      | CWDontPropagate | CWOverrideRedirect, &swa);

      // GetWindowAttributes

      XWindowAttributes wa;
      Status success = XGetWindowAttributes(dpy, w, &wa);

      // DestroyWindow (done)

      // DestroySubwindows

      w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XDestroySubwindows(dpy, w);

      // ChangeSaveSet

//        Display *dpy2 = XOpenDisplay(NIL);
//        assert(dpy2);
//        XAddToSaveSet(dpy2, w);
//        XCloseDisplay(dpy2);

      // ReparentWindow

      w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, 
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XReparentWindow(dpy, w2, w, 10, 5);

      // MapWindow

      XMapWindow(dpy, w);

      // MapSubwindows
      
      XMapSubwindows(dpy, w);

      // UnmapWindow
      
      XUnmapWindow(dpy, w);

      // UnmapSubwindows

      XMapWindow(dpy, w);
      XUnmapSubwindows(dpy, w2);
      XMapSubwindows(dpy, w);

      // ConfigureWindow

      Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2,
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);

      XMapWindow(dpy, w3);

      XWindowChanges wc;
      wc.x = -5;
      wc.y = -10;
      wc.width = 50;
      wc.height = 40;
      wc.border_width = 7;
      wc.sibling = w2;
      wc.stack_mode = Opposite;
      XConfigureWindow(dpy, w3, 
		       CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, 
		       &wc);

      // CirculateWindow

      XCirculateSubwindows(dpy, w, RaiseLowest);

      // GetGeometry

      Window root;
      int x, y;
      unsigned width, height, border_width, depth;
      XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth);

      // QueryTree

      Window parent;
      Window *children;
      unsigned nchildren;
      success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren);
      XFree(children);

      // InternAtom

      Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True);

      // GetAtomName

      char *string = XGetAtomName(dpy, XA_PRIMARY);
      XFree(string);

      // ChangeProperty

      XStoreName(dpy, w, "test window");

      // DeleteProperty

      XDeleteProperty(dpy, w, XA_WM_NAME);

      // GetProperty
      // TODO

      // ListProperties

      int num_prop;
      Atom *list = XListProperties(dpy, w, &num_prop);
      XFree(list);

      // SetSelectionOwner

      XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000);
      XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime);

      // GetSelectionOwner

      Window wx = XGetSelectionOwner(dpy, XA_PRIMARY);

      // ConvertSelection

      XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime);

      // SendEvent

      // GrabPointer

      std::cerr << "Grabbing" << std::endl;
      int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask,
			     GrabModeSync, GrabModeAsync, w, None, CurrentTime);
      XSync(dpy, False);
//      sleep(5);

      // UngrabPointer

      std::cerr << "Ungrabbing" << std::endl;
      XUngrabPointer(dpy, CurrentTime);

      // GrabButton

      XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      // UngrabButton

      XUngrabButton(dpy, 2, LockMask, w);

      // ChangeActivePointerGrab

      XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime);

      // GrabKeyboard

      XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000);

      // UngrabKeyboard

      XUngrabKeyboard(dpy, 13000);

      // GrabKey

      XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync,
	       GrabModeSync);

      // UngrabKey

      XUngrabKey(dpy, AnyKey, AnyModifier, w);

      // AllowEvents

      XAllowEvents(dpy, AsyncPointer, 14000);

      // GrabServer

      XGrabServer(dpy);

      // UngrabServer

      XUngrabServer(dpy);

      // QueryPointer

      Window child;
      int root_x, root_y, win_x, win_y;
      unsigned mask;
      Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask);

      // GetMotionEvents

      int nevents;
      XGetMotionEvents(dpy, w, 15000, 16000, &nevents);

      // TranslateCoordinates

      int dest_x, dest_y;

      XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child);

      // WarpPointer

      XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30);

      // SetInputFocus

      XSetInputFocus(dpy,w, RevertToPointerRoot, 17000);
      XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000);

      // GetInputFocus

      Window focus;
      int revert_to;
      XGetInputFocus(dpy, &focus, &revert_to);

      // QueryKeymap

      char keys_return[32];
      XQueryKeymap(dpy, keys_return);

      // OpenFont

      Font fid = XLoadFont(dpy, "cursor");

      // CloseFont

      XUnloadFont(dpy, fid);

      // QueryFont

      XFontStruct *fs = XLoadQueryFont(dpy, "cursor");
      assert(fs);

      // QueryTextExtents

      int direction, font_ascent, font_descent;
      XCharStruct overall;
      XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall);
      XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall);

      XChar2b c2bs;
      c2bs.byte1 = '$';
      c2bs.byte2 = 'B';
      XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall);

      XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, 
			&font_descent, &overall);

      // ListFonts

      int actual_count;
      char **fontList = XListFonts(dpy, "*", 100, &actual_count);
      XFree((char *)fontList);

      // ListFontsWithInfo

      int count;
      XFontStruct *info;
      char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info);
      XFreeFontInfo(names, info, count);

      // SetFontPath
      // GetFontPath

      int npaths;
      char **charList = XGetFontPath(dpy, &npaths);

      char **charList2 = new char *[npaths + 1];
      memcpy(charList2, charList, npaths * sizeof(char *));
      charList2[npaths] = charList2[0];

      XSetFontPath(dpy, charList2, npaths + 1);
      XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value

      XFreeFontPath(charList);
      delete [] charList2;

      // CreatePixmap

      Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr));

      // FreePixmap

      XFreePixmap(dpy, pix2);

      // CreateGC

      Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), 
					    "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4);

      XGCValues gcv;
      gcv.function = GXand;
      gcv.plane_mask = 0x1;
      gcv.foreground = WhitePixelOfScreen(scr);
      gcv.background = BlackPixelOfScreen(scr);
      gcv.line_width = 2;
      gcv.line_style = LineDoubleDash;
      gcv.cap_style = CapProjecting;
      gcv.join_style = JoinRound;
      gcv.fill_style = FillStippled;
      gcv.fill_rule = EvenOddRule;
      gcv.arc_mode = ArcPieSlice;
      gcv.tile = pixmap;
      gcv.stipple = bitmap;
      gcv.ts_x_origin = 3;
      gcv.ts_y_origin = 4;
      gcv.font = fs -> fid;
      gcv.subwindow_mode = ClipByChildren;
      gcv.graphics_exposures = True;
      gcv.clip_x_origin = 5;
      gcv.clip_y_origin = 6;
      gcv.clip_mask = bitmap;
      gcv.dash_offset = 1;
      gcv.dashes = 0xc2;
      
      GC gc = XCreateGC(dpy, w, 
			  GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth
			| GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile
			| GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode
			| GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset
			| GCDashList | GCArcMode,
			&gcv);

      // ChangeGC

      gcv.function = GXandReverse;

      // Only a few of these should appear, since the values are cached on the client side by the Xlib.

      XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv);

      // CopyGC
      
      GC gc2 = XCreateGC(dpy, w, 0, NIL);
      XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2);

      // SetDashes

      XSetDashes(dpy, gc, 3, "\001\377\001", 3);

      // SetClipRectangles

      XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } };
      XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted);

      // FreeGC

	    // done already

      // ClearArea

      XClearArea(dpy, w, 30, 10, 10, 100, False);

      // CopyArea

      XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10);

      // CopyPlane

      // This won't work if the Screen doesn't have at least 3 planes
      XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4);

      // PolyPoint

      XDrawPoint(dpy, w, gc, 1, 2);

      XPoint points[] = { { 3, 4 }, { 5, 6 } };
      XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin);

      // PolyLine

      XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious);

      // PolySegment

      XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
      XDrawSegments(dpy, w, gc, segments, SIZEOF(segments));

      // PolyRectangle

      XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyArc

      XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, 
		      { 10, 20, 30, 40, 50, -30 } };

      XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // FillPoly

      XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious);

      // PolyFillRectangle
      
      XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyFillArc
      
      XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // PutImage
      // GetImage

      XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap);
      XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30);
      XSync(dpy, False); // Make the next request starts at the beginning of a packet

      // PolyText8
      XTextItem textItems[3];
      textItems[0].chars = "toto";
      textItems[0].nchars = strlen(textItems[0].chars);
      textItems[0].delta = -3;
      textItems[0].font = fs->fid;
      textItems[1].chars = "titi";
      textItems[1].nchars = strlen(textItems[1].chars);
      textItems[1].delta = 3;
      textItems[1].font = None;
      textItems[2].chars = "tutu";
      textItems[2].nchars = strlen(textItems[2].chars);
      textItems[2].delta = 0;
      textItems[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems, 3);


      XTextItem textItems2[3];
      textItems2[0].chars = "totox";
      textItems2[0].nchars = strlen(textItems2[0].chars);
      textItems2[0].delta = -3;
      textItems2[0].font = fs->fid;
      textItems2[1].chars = "titi";
      textItems2[1].nchars = strlen(textItems2[1].chars);
      textItems2[1].delta = 3;
      textItems2[1].font = None;
      textItems2[2].chars = "tutu";
      textItems2[2].nchars = strlen(textItems2[2].chars);
      textItems2[2].delta = 0;
      textItems2[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems2, 3);

      // PolyText16

      XChar2b c2b2[] = { 0, 't', 0, 'x' };

      XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } };
      XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16));

      // ImageText8

      XDrawImageString(dpy, w, gc, 10, 10, "toto", 4);

      // ImageText16

      XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1);
      XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2);

      // CreateColormap
      // Don't forget to tell the kids how it was when we had only 8 bits per pixel.

      Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // FreeColormap

      XFreeColormap(dpy, colormap);
      colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // CopyColormapAndFree

      Colormap colormap2 = XCopyColormapAndFree(dpy, colormap);

      // InstallColormap

      XInstallColormap(dpy, colormap2);

      // UninstallColormap

      XUninstallColormap(dpy, colormap2);

      // ListInstalledColormaps

      int num;
      Colormap *colormapList = XListInstalledColormaps(dpy, w, &num);

      // AllocColor

      XColor screen;
      screen.red = 0;
      screen.green = 32767;
      screen.blue = 65535;
      screen.flags = DoRed | DoGreen | DoBlue;
      success = XAllocColor(dpy, colormap, &screen);

      // AllocNamedColor

      XColor screen2, exact;
      success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact);

      // AllocColorCells

      unsigned long plane_masks, pixels;
      success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1);

      // AllocColorPlanes

      unsigned long rmask, gmask, bmask;
      success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask);

      // FreeColors

      unsigned long pixels2[2] = { screen.pixel, screen2.pixel };
      XFreeColors(dpy, colormap, pixels2, 2, 0);

      // StoreColors

      success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2);

      // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells
      // I want my requests to be sent, however.
      if (!success) {
	    XSetErrorHandler(errorHandler);
      }

      XColor colors[2];
      colors[0] = screen;  colors[0].pixel = pixels2[0];
      colors[1] = screen2; colors[1].pixel = pixels2[1];
      XStoreColors(dpy, colormap, colors, 2);

      // StoreNamedColor

      XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue);

      XSync(dpy, False);
      XSetErrorHandler(NIL); // Restore the default handler

      // QueryColors

      screen2.pixel = WhitePixelOfScreen(scr);
      XQueryColor(dpy, colormap, &screen2);

      // LookupColor

      success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen);

      // CreateCursor

      Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10);

      // CreateGlyphCursor
      
      Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors);

      // FreeCursor
      
      XFreeCursor(dpy, cursor2);

      // RecolorCursor

      XRecolorCursor(dpy, cursor, colors, &exact);

      // QueryBestSize

      success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height);

      // QueryExtension

      int major_opcode, first_event, first_error;
      XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error);

      // ListExtensions

      int nextensions;
      char **extensionList = XListExtensions(dpy, &nextensions);
      for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl;
      XFree(extensionList);

      // ChangeKeyboardMapping
      // GetKeyboardMapping

      int min_keycodes, max_keycodes;
      XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes);

      int keysyms_per_keycode;
      KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1,
					    &keysyms_per_keycode);
      XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, 
			     max_keycodes - min_keycodes + 1);

      // ChangeKeyboardControl
      // GetKeyboardControl

      XKeyboardState keyboardState;
      XGetKeyboardControl(dpy, &keyboardState);

      XKeyboardControl keyboardValues;
      keyboardValues.key_click_percent = keyboardState.key_click_percent;
      keyboardValues.bell_percent = keyboardState.bell_percent;
      keyboardValues.bell_pitch = keyboardState.bell_pitch;
      keyboardValues.bell_duration = keyboardState.bell_duration;
      keyboardValues.led = 1;
      keyboardValues.led_mode = LedModeOn;
      keyboardValues.key = min_keycodes;
      keyboardValues.auto_repeat_mode = AutoRepeatModeDefault;
      XChangeKeyboardControl(dpy, 
			       KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration
			     | KBLed | KBLedMode | KBKey | KBAutoRepeatMode,
			     &keyboardValues);

      // Bell

      XBell(dpy, 90);

      // ChangePointerControl
      // GetPointerControl

      int accel_numerator, accel_denominator, threshold;
      XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold);

      XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold);

      // SetScreenSaver
      // GetScreenSaver

      int timeout, interval, prefer_blanking, allow_exposures;
      XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures);
      XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures);

      // ChangeHosts
      // ListHosts

      int nhosts;
      Bool state;
      XHostAddress *hostList = XListHosts(dpy, &nhosts, &state);

      XHostAddress host;
      host.family = FamilyInternet;
      host.length = 4;
      host.address = "\001\002\003\004";
      XAddHost(dpy, &host);

      // SetAccessControl

      XSetAccessControl(dpy, EnableAccess);

      // SetCloseDownMode

      XSetCloseDownMode(dpy, RetainTemporary);

      // KillClient

      XKillClient(dpy, AllTemporary);

      // RotateProperties

      Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), 
			    XInternAtom(dpy, "CUT_BUFFER1", False),
			    XInternAtom(dpy, "CUT_BUFFER2", False) };
      XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1);

      // ForceScreenSaver

      XForceScreenSaver(dpy, ScreenSaverReset);

      // SetPointerMapping
      // GetPointerMapping

      unsigned char map[64];
      int map_length = XGetPointerMapping(dpy, map, 64);
      XSetPointerMapping(dpy, map, map_length);

      // SetModifierMapping
      // GetModifierMapping

      XModifierKeymap *modmap = XGetModifierMapping(dpy);
      XSetModifierMapping(dpy, modmap);

      // NoOperation

      XNoOp(dpy);

      for(;;) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    std::cout << "Got an event of type " << e.type << std::endl;
      }
}
Esempio n. 13
0
int main(int argc, char **argv)
{
	Display *dpy;
	int i;
	int buffer = -1;
	char *filename = NULL;
	FILE *file = stdin;
	char *buf = NULL;
	char *display_name = "";
	int l = 0;
	int buf_len = 0;
	int limit_check = 1;
	int clear_selection = 0;

	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
				print_help();
				exit(0);
			} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
				printf("%s (Window Maker %s)\n", __progname, VERSION);
				exit(0);
			} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
				if (i < argc - 1) {
					i++;
					if (sscanf(argv[i], "%i", &buffer) != 1) {
						fprintf(stderr, "%s: could not convert '%s' to int\n",
							__progname, argv[i]);
						exit(1);
					}
					if (buffer < 0 || buffer > 7) {
						fprintf(stderr, "%s: invalid buffer number %i\n", __progname, buffer);
						exit(1);
					}
				} else {
					printf("%s: missing argument for '%s'\n", __progname, argv[i]);
					printf("Try '%s --help' for more information\n", __progname);
					exit(1);
				}
			} else if (strcmp(argv[i], "-display") == 0) {
				if (i < argc - 1) {
					display_name = argv[++i];
				} else {
					printf("%s: missing argument for '%s'\n", __progname, argv[i]);
					printf("Try '%s --help' for more information\n", __progname);
					exit(1);
				}
			} else if (strcmp(argv[i], "-clearselection") == 0
				   || strcmp(argv[i], "--clear-selection") == 0) {
				clear_selection = 1;
			} else if (strcmp(argv[i], "-nolimit") == 0 || strcmp(argv[i], "--no-limit") == 0) {
				limit_check = 0;
			} else {
				printf("%s: invalid argument '%s'\n", __progname, argv[i]);
				printf("Try '%s --help' for more information\n", __progname);
				exit(1);
			}
		} else {
			filename = argv[i];
		}
	}
	if (filename) {
		file = fopen(filename, "rb");
		if (!file) {
			char line[1024];
			sprintf(line, "%s: could not open \"%s\"", __progname, filename);
			perror(line);
			exit(1);
		}
	}

	dpy = XOpenDisplay(display_name);
	XSetErrorHandler(errorHandler);
	if (!dpy) {
		fprintf(stderr, "%s: could not open display \"%s\"\n", __progname, XDisplayName(display_name));
		exit(1);
	}

	if (buffer < 0) {
		Atom *rootWinProps;
		int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
		int i, count;

		/* Create missing CUT_BUFFERs */
		rootWinProps = XListProperties(dpy, DefaultRootWindow(dpy), &count);
		for (i = 0; i < count; i++) {
			switch (rootWinProps[i]) {
			case XA_CUT_BUFFER0:
				exists[0] = 1;
				break;
			case XA_CUT_BUFFER1:
				exists[1] = 1;
				break;
			case XA_CUT_BUFFER2:
				exists[2] = 1;
				break;
			case XA_CUT_BUFFER3:
				exists[3] = 1;
				break;
			case XA_CUT_BUFFER4:
				exists[4] = 1;
				break;
			case XA_CUT_BUFFER5:
				exists[5] = 1;
				break;
			case XA_CUT_BUFFER6:
				exists[6] = 1;
				break;
			case XA_CUT_BUFFER7:
				exists[7] = 1;
				break;
			default:
				break;
			}
		}
		if (rootWinProps) {
			XFree(rootWinProps);
		}
		for (i = 0; i < 8; i++) {
			if (!exists[i]) {
				XStoreBuffer(dpy, "", 0, i);
			}
		}

		XRotateBuffers(dpy, 1);
		buffer = 0;
	}

	while (!feof(file)) {
		char *nbuf;
		char tmp[LINESIZE + 2];
		int nl = 0;

		/*
		 * Use read() instead of fgets() to preserve NULLs, since
		 * especially since there's no reason to read one line at a time.
		 */
		if ((nl = fread(tmp, 1, LINESIZE, file)) <= 0) {
			break;
		}
		if (buf_len == 0) {
			nbuf = malloc(buf_len = l + nl + 1);
		} else if (buf_len < l + nl + 1) {
			/*
			 * To avoid terrible performance on big input buffers,
			 * grow by doubling, not by the minimum needed for the
			 * current line.
			 */
			buf_len = 2 * buf_len + nl + 1;
			/* some realloc implementations don't do malloc if buf==NULL */
			if (buf == NULL) {
				nbuf = malloc(buf_len);
			} else {
				nbuf = realloc(buf, buf_len);
			}
		} else {
			nbuf = buf;
		}
		if (!nbuf) {
			fprintf(stderr, "%s: out of memory\n", __progname);
			exit(1);
		}
		buf = nbuf;
		/*
		 * Don't strcat, since it would make the algorithm n-squared.
		 * Don't use strcpy, since it stops on a NUL.
		 */
		memcpy(buf + l, tmp, nl);
		l += nl;
		if (limit_check && l >= MAXDATA) {
			fprintf
			    (stderr,
			     "%s: too much data in input - more than %d bytes\n"
			     "  use the -nolimit argument to remove the limit check.\n", __progname, MAXDATA);
			exit(1);
		}
	}

	if (clear_selection) {
		XSetSelectionOwner(dpy, XA_PRIMARY, None, CurrentTime);
	}
	if (buf) {
		XStoreBuffer(dpy, buf, l, buffer);
	}
	XFlush(dpy);
	XCloseDisplay(dpy);
	exit(buf == NULL || errno != 0);
}
int
main (int argc, char **argv)
{
  Display *xdisplay;
  int i;
  int n_left;
  int n_props;
  Window window;
  const char *window_str;
  char *end;
  Atom *props;
  struct timeval current_time;
  
  if (argc < 2)
    {
      fprintf (stderr, "specify window ID\n");
      return 1;
    }
  
  window_str = argv[1];

  end = NULL;
  window = strtoul (window_str, &end, 0);
  if (end == NULL || *end != '\0')
    {
      fprintf (stderr, "\"%s\" does not parse as a window ID\n", window_str);
      return 1;
    }

  xdisplay = XOpenDisplay (NULL);
  if (xdisplay == NULL)
    {
      fprintf (stderr, "Could not open display\n");
      return 1;
    }

  if (getenv ("MARCO_SYNC") != NULL)
    XSynchronize (xdisplay, True);

  XSetErrorHandler (x_error_handler);
  
  n_props = 0;
  props = XListProperties (xdisplay, window, &n_props);
  if (n_props == 0 || props == NULL)
    {
      fprintf (stderr, "Window has no properties\n");
      return 1;
    }

  gettimeofday (&program_start_time, NULL);
  
  i = 0;
  while (i < n_props)
    {
      gettimeofday (&current_time, NULL);
      printf (" %gms (sending request for property %ld)\n",
              ELAPSED (program_start_time, current_time),
              props[i]);
      if (ag_task_create (xdisplay,
                          window, props[i],
                          0, 0xffffffff,
                          False,
                          AnyPropertyType) == NULL)
        {
          fprintf (stderr, "Failed to send request\n");
          return 1;
        }
      
      ++i;
    }

  XFree (props);
  props = NULL;

  n_left = n_props;
  
  while (TRUE)
    {
      XEvent xevent;
      int connection;
      fd_set set;
      AgGetPropertyTask *task;
      
      /* Mop up event queue */
      while (XPending (xdisplay) > 0)
        {                  
          XNextEvent (xdisplay, &xevent);
          gettimeofday (&current_time, NULL);
          printf (" %gms (processing event type %d)\n",
                  ELAPSED (program_start_time, current_time),
                  xevent.xany.type);
        }
      
      while ((task = ag_get_next_completed_task (xdisplay)))
        {
          try_get_reply (xdisplay, task);
          n_left -= 1;
        }

      if (n_left == 0)
        {
          printf ("All %d replies received.\n", n_props);
          break;
        }

      /* Wake up if we may have a reply */
      connection = ConnectionNumber (xdisplay);

      FD_ZERO (&set);
      FD_SET (connection, &set);

      gettimeofday (&current_time, NULL);
      printf (" %gms (blocking for data %d left)\n",
              ELAPSED (program_start_time, current_time), n_left);
      select (connection + 1, &set, NULL, NULL, NULL);
    }

  run_speed_comparison (xdisplay, window);
  
  return 0;
}
Esempio n. 15
0
WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
{
	W_Screen *scrPtr;
	XGCValues gcv;
	Pixmap stipple;
	static int initialized = 0;
	static char *atomNames[] = {
		"_GNUSTEP_WM_ATTR",
		"WM_DELETE_WINDOW",
		"WM_PROTOCOLS",
		"CLIPBOARD",
		"XdndAware",
		"XdndSelection",
		"XdndEnter",
		"XdndLeave",
		"XdndPosition",
		"XdndDrop",
		"XdndFinished",
		"XdndTypeList",
		"XdndActionList",
		"XdndActionDescription",
		"XdndStatus",
		"XdndActionCopy",
		"XdndActionMove",
		"XdndActionLink",
		"XdndActionAsk",
		"XdndActionPrivate",
		"_WINGS_DND_MOUSE_OFFSET",
		"WM_STATE",
		"UTF8_STRING",
		"_NET_WM_NAME",
		"_NET_WM_ICON_NAME",
		"_NET_WM_ICON",
	};
	Atom atoms[wlengthof(atomNames)];
	int i;

	if (!initialized) {

		initialized = 1;

		W_ReadConfigurations();

		assert(W_ApplicationInitialized());
	}

	scrPtr = malloc(sizeof(W_Screen));
	if (!scrPtr)
		return NULL;
	memset(scrPtr, 0, sizeof(W_Screen));

	scrPtr->aflags.hasAppIcon = 1;

	scrPtr->display = display;
	scrPtr->screen = screen;
	scrPtr->rcontext = context;

	scrPtr->depth = context->depth;

	scrPtr->visual = context->visual;
	scrPtr->lastEventTime = 0;

	scrPtr->colormap = context->cmap;

	scrPtr->rootWin = RootWindow(display, screen);

	scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);

	scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);

	/* Create missing CUT_BUFFERs */
	{
		Atom *rootWinProps;
		int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
		int count;

		rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
		for (i = 0; i < count; i++) {
			switch (rootWinProps[i]) {
			case XA_CUT_BUFFER0:
				exists[0] = 1;
				break;
			case XA_CUT_BUFFER1:
				exists[1] = 1;
				break;
			case XA_CUT_BUFFER2:
				exists[2] = 1;
				break;
			case XA_CUT_BUFFER3:
				exists[3] = 1;
				break;
			case XA_CUT_BUFFER4:
				exists[4] = 1;
				break;
			case XA_CUT_BUFFER5:
				exists[5] = 1;
				break;
			case XA_CUT_BUFFER6:
				exists[6] = 1;
				break;
			case XA_CUT_BUFFER7:
				exists[7] = 1;
				break;
			default:
				break;
			}
		}
		if (rootWinProps) {
			XFree(rootWinProps);
		}
		for (i = 0; i < 8; i++) {
			if (!exists[i]) {
				XStoreBuffer(display, "", 0, i);
			}
		}
	}

	scrPtr->ignoredModifierMask = 0;
	{
		int i;
		XModifierKeymap *modmap;
		KeyCode nlock, slock;
		static int mask_table[8] = {
			ShiftMask, LockMask, ControlMask, Mod1Mask,
			Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
		};
		unsigned int numLockMask = 0, scrollLockMask = 0;

		nlock = XKeysymToKeycode(display, XK_Num_Lock);
		slock = XKeysymToKeycode(display, XK_Scroll_Lock);

		/*
		 * Find out the masks for the NumLock and ScrollLock modifiers,
		 * so that we can bind the grabs for when they are enabled too.
		 */
		modmap = XGetModifierMapping(display);

		if (modmap != NULL && modmap->max_keypermod > 0) {
			for (i = 0; i < 8 * modmap->max_keypermod; i++) {
				if (modmap->modifiermap[i] == nlock && nlock != 0)
					numLockMask = mask_table[i / modmap->max_keypermod];
				else if (modmap->modifiermap[i] == slock && slock != 0)
					scrollLockMask = mask_table[i / modmap->max_keypermod];
			}
		}

		if (modmap)
			XFreeModifiermap(modmap);

		scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
	}

	/* initially allocate some colors */
	WMWhiteColor(scrPtr);
	WMBlackColor(scrPtr);
	WMGrayColor(scrPtr);
	WMDarkGrayColor(scrPtr);

	gcv.graphics_exposures = False;

	gcv.function = GXxor;
	gcv.foreground = W_PIXEL(scrPtr->white);
	if (gcv.foreground == 0)
		gcv.foreground = 1;
	scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
				  | GCGraphicsExposures | GCForeground, &gcv);

	gcv.function = GXxor;
	gcv.foreground = W_PIXEL(scrPtr->gray);
	gcv.subwindow_mode = IncludeInferiors;
	scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
				   | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);

	gcv.function = GXcopy;
	scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);

	scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);

	stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
	gcv.foreground = W_PIXEL(scrPtr->darkGray);
	gcv.background = W_PIXEL(scrPtr->gray);
	gcv.fill_style = FillStippled;
	gcv.stipple = stipple;
	scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
				      GCForeground | GCBackground | GCStipple
				      | GCFillStyle | GCGraphicsExposures, &gcv);

	scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
	scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);

	/* we need a 1bpp drawable for the monoGC, so borrow this one */
	scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);

	scrPtr->stipple = stipple;

	scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;

	scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);

	scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);

	if (!scrPtr->boldFont)
		scrPtr->boldFont = scrPtr->normalFont;

	if (!scrPtr->normalFont) {
		wwarning(_("could not load any fonts. Make sure your font installation"
			   " and locale settings are correct."));

		return NULL;
	}

	/* create input method stuff */
	W_InitIM(scrPtr);

	scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
						CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);

	scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
						 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);

	scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
						RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);

	scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
						 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);

	scrPtr->tristateButtonImageOn = makePixmap(scrPtr, TRISTATE_BUTTON_ON,
	                                           TRISTATE_BUTTON_ON_WIDTH, TRISTATE_BUTTON_ON_HEIGHT, False);

	scrPtr->tristateButtonImageOff = makePixmap(scrPtr, TRISTATE_BUTTON_OFF,
	                                            TRISTATE_BUTTON_OFF_WIDTH, TRISTATE_BUTTON_OFF_HEIGHT, False);

	scrPtr->tristateButtonImageTri = makePixmap(scrPtr, TRISTATE_BUTTON_TRI,
	                                            TRISTATE_BUTTON_TRI_WIDTH, TRISTATE_BUTTON_TRI_HEIGHT, False);

	scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);

	scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
					       BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);

	scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
					    SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);

	scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
				     SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);

	scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
				       SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);

	scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
				       SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);

	scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
					SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);

	scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
				       SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);

	scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
					 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);

	scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
					 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);

	scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
					  SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);

	scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
					    POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);

	scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
					       PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);

	scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);

	loadPixmaps(scrPtr);

	scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);

	scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);

	{
		XColor bla;
		Pixmap blank;

		blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
		XSetForeground(display, scrPtr->monoGC, 0);
		XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);

		scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
		XFreePixmap(display, blank);
	}

#ifdef HAVE_XINTERNATOMS
	XInternAtoms(display, atomNames, wlengthof(atomNames), False, atoms);
#else
	for (i = 0; i < wlengthof(atomNames); i++) {
		atoms[i] = XInternAtom(display, atomNames[i], False);
	}
#endif

	i = 0;
	scrPtr->attribsAtom = atoms[i++];

	scrPtr->deleteWindowAtom = atoms[i++];

	scrPtr->protocolsAtom = atoms[i++];

	scrPtr->clipboardAtom = atoms[i++];

	scrPtr->xdndAwareAtom = atoms[i++];
	scrPtr->xdndSelectionAtom = atoms[i++];
	scrPtr->xdndEnterAtom = atoms[i++];
	scrPtr->xdndLeaveAtom = atoms[i++];
	scrPtr->xdndPositionAtom = atoms[i++];
	scrPtr->xdndDropAtom = atoms[i++];
	scrPtr->xdndFinishedAtom = atoms[i++];
	scrPtr->xdndTypeListAtom = atoms[i++];
	scrPtr->xdndActionListAtom = atoms[i++];
	scrPtr->xdndActionDescriptionAtom = atoms[i++];
	scrPtr->xdndStatusAtom = atoms[i++];

	scrPtr->xdndActionCopy = atoms[i++];
	scrPtr->xdndActionMove = atoms[i++];
	scrPtr->xdndActionLink = atoms[i++];
	scrPtr->xdndActionAsk = atoms[i++];
	scrPtr->xdndActionPrivate = atoms[i++];

	scrPtr->wmIconDragOffsetAtom = atoms[i++];

	scrPtr->wmStateAtom = atoms[i++];

	scrPtr->utf8String = atoms[i++];
	scrPtr->netwmName = atoms[i++];
	scrPtr->netwmIconName = atoms[i++];
	scrPtr->netwmIcon = atoms[i++];

	scrPtr->rootView = W_CreateRootView(scrPtr);

	scrPtr->balloon = W_CreateBalloon(scrPtr);

	W_InitApplication(scrPtr);

	return scrPtr;
}