Esempio n. 1
0
void WMScreenMainLoop(WMScreen * scr)
{
	XEvent event;

	while (1) {
		WMNextEvent(scr->display, &event);
		WMHandleEvent(&event);
	}
}
Esempio n. 2
0
static char*
captureShortcut(Display *dpy, _Panel *panel)
{
    XEvent ev;
    KeySym ksym;
    char buffer[64];
    char *key = NULL;

    while (panel->capturing) {
        XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
        WMNextEvent(dpy, &ev);
        if (ev.type==KeyPress && ev.xkey.keycode!=0) {
            ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
            if (!IsModifierKey(ksym)) {
                key=XKeysymToString(ksym);
                panel->capturing = 0;
                break;
            }
        }
        WMHandleEvent(&ev);
    }

    if (!key)
        return NULL;

    buffer[0] = 0;

    if (ev.xkey.state & ControlMask) {
        strcat(buffer, "Control+");
    }
    if (ev.xkey.state & ShiftMask) {
        strcat(buffer, "Shift+");
    }
    if (ev.xkey.state & Mod1Mask) {
        strcat(buffer, "Mod1+");
    }
    if (ev.xkey.state & Mod2Mask) {
        strcat(buffer, "Mod2+");
    }
    if (ev.xkey.state & Mod3Mask) {
        strcat(buffer, "Mod3+");
    }
    if (ev.xkey.state & Mod4Mask) {
        strcat(buffer, "Mod4+");
    }
    if (ev.xkey.state & Mod5Mask) {
        strcat(buffer, "Mod5+");
    }
    strcat(buffer, key);

    return wstrdup(buffer);
}
Esempio n. 3
0
void ResetGame(void)
{
    int i, x, y, ox, oy;
    
    
    MoveCount = 0;
    
    for (i = 0; i < Size*Size-1; i++) {
	Map[i] = i;
    }
    Map[i] = -1;
    ox = x = Size-1;
    oy = y = Size-1;
    for (i = 0; i < 5; i++) {
	int ok;
	ok = 1;
	switch (rand()%4) {
	 case 0:
	    if (x > 0) x--; else ok = 0;
	    break;
	 case 2:
	    if (x < Size-1) x++; else ok = 0;
	    break;
	 case 1:
	    if (y > 0) y--; else ok = 0;
	    break;
	 case 3:
	    if (y < Size-1) y++; else ok = 0;
	    break;
	}
	if (ok) {
	    MoveButton(MAP(x,y), ox, oy);

	    SWAP(MAP(ox, oy), MAP(x, y));
	    
	    while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
		XEvent ev;
		WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
		WMHandleEvent(&ev);
	    }
	    ox = x;
	    oy = y;
	}
    }
}
Esempio n. 4
0
void WMRunModalLoop(WMScreen * scr, WMView * view)
{
	/* why is scr passed if is determined from the view? */
	/*WMScreen *scr = view->screen; */
	int oldModalLoop = scr->modalLoop;
	WMView *oldModalView = scr->modalView;

	scr->modalView = view;

	scr->modalLoop = 1;
	while (scr->modalLoop) {
		XEvent event;

		WMNextEvent(scr->display, &event);
		WMHandleEvent(&event);
	}

	scr->modalView = oldModalView;
	scr->modalLoop = oldModalLoop;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
	Display *dpy;
	WMScreen *scr;
	char *path;
	int i;
	char *display_name = "";

	wsetabort(wAbort);

	memset(DeadHandlers, 0, sizeof(DeadHandlers));

	WMInitializeApplication("WPrefs", &argc, argv);

	WMSetResourcePath(RESOURCE_PATH);
	path = WMPathForResourceOfType("WPrefs.tiff", NULL);
	if (!path) {
		/* maybe it is run directly from the source directory */
		WMSetResourcePath(".");
		path = WMPathForResourceOfType("WPrefs.tiff", NULL);
		if (!path) {
			WMSetResourcePath("..");
		}
	}
	if (path) {
		wfree(path);
	}

	if (argc > 1) {
		for (i = 1; i < argc; i++) {
			if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
				printf("WPrefs (Window Maker) %s\n", VERSION);
				exit(0);
			} else if (strcmp(argv[i], "-display") == 0) {
				i++;
				if (i >= argc) {
					wwarning(_("too few arguments for %s"), argv[i - 1]);
					exit(0);
				}
				display_name = argv[i];
			} else {
				print_help(argv[0]);
				exit(0);
			}
		}
	}

	setlocale(LC_ALL, "");

#ifdef I18N
	if (getenv("NLSPATH"))
		bindtextdomain("WPrefs", getenv("NLSPATH"));
	else
		bindtextdomain("WPrefs", LOCALEDIR);
	bind_textdomain_codeset("WPrefs", "UTF-8");
	textdomain("WPrefs");

	if (!XSupportsLocale()) {
		wwarning(_("X server does not support locale"));
	}
	if (XSetLocaleModifiers("") == NULL) {
		wwarning(_("cannot set locale modifiers"));
	}
#endif

	dpy = XOpenDisplay(display_name);
	if (!dpy) {
		wfatal(_("could not open display %s"), XDisplayName(display_name));
		exit(0);
	}
#if 0
	XSynchronize(dpy, 1);
#endif
	scr = WMCreateScreen(dpy, DefaultScreen(dpy));
	if (!scr) {
		wfatal(_("could not initialize application"));
		exit(0);
	}

	xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);

	WMPLSetCaseSensitive(False);

	Initialize(scr);

	while (1) {
		XEvent event;

		WMNextEvent(dpy, &event);

		while (DeadChildrenCount-- > 0) {
			int i;

			for (i = 0; i < MAX_DEATHS; i++) {
				if (DeadChildren[i] == DeadHandlers[i].pid) {
					(*DeadHandlers[i].handler) (DeadHandlers[i].data);
					DeadHandlers[i].pid = 0;
				}
			}
		}

		WMHandleEvent(&event);
	}
}
Esempio n. 6
0
/*
 *-----------------------------------------------------------------------
 * manageAllWindows--
 * 	Manages all windows in the screen.
 *
 * Notes:
 * 	Called when the wm is being started.
 *	No events can be processed while the windows are being
 * reparented/managed.
 *-----------------------------------------------------------------------
 */
static void manageAllWindows(WScreen * scr, int crashRecovery)
{
	Window root, parent;
	Window *children;
	unsigned int nchildren;
	unsigned int i, j;
	WWindow *wwin;

	XGrabServer(dpy);
	XQueryTree(dpy, scr->root_win, &root, &parent, &children, &nchildren);

	scr->flags.startup = 1;

	/* first remove all icon windows */
	for (i = 0; i < nchildren; i++) {
		XWMHints *wmhints;

		if (children[i] == None)
			continue;

		wmhints = XGetWMHints(dpy, children[i]);
		if (wmhints && (wmhints->flags & IconWindowHint)) {
			for (j = 0; j < nchildren; j++) {
				if (children[j] == wmhints->icon_window) {
					XFree(wmhints);
					wmhints = NULL;
					children[j] = None;
					break;
				}
			}
		}
		if (wmhints) {
			XFree(wmhints);
		}
	}

	for (i = 0; i < nchildren; i++) {
		if (children[i] == None)
			continue;

		wwin = wManageWindow(scr, children[i]);
		if (wwin) {
			/* apply states got from WSavedState */
			/* shaded + minimized is not restored correctly */
			if (wwin->flags.shaded) {
				wwin->flags.shaded = 0;
				wShadeWindow(wwin);
			}
			if (wwin->flags.miniaturized
			    && (wwin->transient_for == None
				|| wwin->transient_for == scr->root_win
				|| !windowInList(wwin->transient_for, children, nchildren))) {

				wwin->flags.skip_next_animation = 1;
				wwin->flags.miniaturized = 0;
				wIconifyWindow(wwin);
			} else {
				wClientSetState(wwin, NormalState, None);
			}
			if (crashRecovery) {
				int border;

				border = (!HAS_BORDER(wwin) ? 0 : scr->frame_border_width);

				wWindowMove(wwin, wwin->frame_x - border,
					    wwin->frame_y - border -
					    (wwin->frame->titlebar ? wwin->frame->titlebar->height : 0));
			}
		}
	}
	XUngrabServer(dpy);

	/* hide apps */
	wwin = scr->focused_window;
	while (wwin) {
		if (wwin->flags.hidden) {
			WApplication *wapp = wApplicationOf(wwin->main_window);

			if (wapp) {
				wwin->flags.hidden = 0;
				wHideApplication(wapp);
			} else {
				wwin->flags.hidden = 0;
			}
		}
		wwin = wwin->prev;
	}

	XFree(children);
	scr->flags.startup = 0;
	scr->flags.startup2 = 1;

	while (XPending(dpy)) {
		XEvent ev;
		WMNextEvent(dpy, &ev);
		WMHandleEvent(&ev);
	}
	w_global.workspace.last_used = 0;
	wWorkspaceForceChange(scr, 0);
	if (!wPreferences.flags.noclip)
		wDockShowIcons(w_global.workspace.array[w_global.workspace.current]->clip);
	scr->flags.startup2 = 0;
}