Example #1
0
int main(int argc, char **argv)
{
	XClassHint classhint;

	dpy = XOpenDisplay("");
	if (!dpy) {
		puts("could not open display!");
		exit(1);
	}
	delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);

	leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
	/* set class hint */
	classhint.res_name = "test";
	classhint.res_class = "Test";
	XSetClassHint(dpy, leader, &classhint);

	/* set window group leader to self */
	hints = XAllocWMHints();
	hints->window_group = leader;
	hints->flags = WindowGroupHint;
	XSetWMHints(dpy, leader, hints);

	/* create app context */
	app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
	menu = WMMenuCreate(app, "Test Menu");
	submenu = WMMenuCreate(app, "File");
	WMMenuAddSubmenu(menu, "File", submenu);

	WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
	WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "New", (WMMenuAction) newwin, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Open", (WMMenuAction) callback, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Save", (WMMenuAction) callback, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Save As...", (WMMenuAction) callback, NULL, NULL, NULL);

	WMAppSetMainMenu(app, menu);

	WMRealizeMenus(app);

	/* set command to use to startup this */
	XSetCommand(dpy, leader, argv, argc);

	/* create first window */
	newwin(NULL, 0, 0);

	XFlush(dpy);
	puts("Run xprop on the test window to see the properties defined");
	while (wincount > 0) {
		XEvent ev;
		XNextEvent(dpy, &ev);
		if (ev.type == ClientMessage) {
			if (ev.xclient.data.l[0] == delete_win) {
				XDestroyWindow(dpy, ev.xclient.window);
				wincount--;
			} else if (ev.xclient.data.l[0] == miniaturize_win) {
				puts("You've pushed the maximize window button");
			}
		}
		WMProcessEvent(app, &ev);
	}
	exit(0);
}
Example #2
0
int main(int argc, char **argv)
{
    XClassHint classhint;

    dpy = XOpenDisplay("");
    if (!dpy) {
        puts("could not open display!");
        exit(1);
    }
    delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);

    leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
                                 0, 0, 0);
    /* set class hint */
    classhint.res_name = "notest";
    classhint.res_class = "Notest";
    XSetClassHint(dpy, leader, &classhint);

    /* set window group leader to self */
    hints = XAllocWMHints();
    hints->window_group = leader;
    hints->flags = WindowGroupHint;
    XSetWMHints(dpy, leader, hints);

    /* create app context */
    app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
    menu = WMMenuCreate(app, "Notify Test Menu");
    WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
    WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);

    WMAppSetMainMenu(app, menu);
    WMRealizeMenus(app);

    /* Get some WindowMaker notifications */
    WMNotifySet( app, WMN_APP_START, notify_print, (void *) "App start" );
    WMNotifySet( app, WMN_APP_EXIT,  notify_print, (void *) "App end" );
    WMNotifySet( app, WMN_WIN_FOCUS,  notify_print, (void *) "Focus in" );
    WMNotifySet( app, WMN_WIN_UNFOCUS,  notify_print, (void *) "Focus out" );
    WMNotifySet( app, WMN_NOTIFY_ALL,  notify_print, (void *) "Unknown type" );
    WMNotifyMaskUpdate( app );	/* Mask isn't actually set till we do this */

    /* set command to use to startup this */
    XSetCommand(dpy, leader, argv, argc);

    /* create first window */
    newwin(NULL, 0, 0);


    XFlush(dpy);
    while( 1 ) {
        XEvent ev;
        XNextEvent(dpy, &ev);
        if (ev.type==ClientMessage) {
            if (ev.xclient.data.l[0]==delete_win) {
                XDestroyWindow(dpy,ev.xclient.window);
                break;
            }
        }
        WMProcessEvent(app, &ev);
    }
    exit(0);
}