/* ---------------------------------------------------------------- *\ file : space_dapp.c author : m. gumz copyr : copyright (c) 2006 by m. gumz license : MIT - license start : Sun Sep 17 15:41:56 2006 \* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- *\ about : simplest way for a dockapp i could come up with. use it to go further if you want. compile with: gcc -o space_dapp space_dapp.c -I/usr/include/X11/ -lX11 \* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- *\ includes \* ---------------------------------------------------------------- */ #include #include #include #include #include #include #include /* ---------------------------------------------------------------- *\ \* ---------------------------------------------------------------- */ char dock_name[] = "space_dapp"; void usage() { printf("%s [width] [height]\n", dock_name); } int main(int argc, char* argv[]) { int w = -1; int h = -1; Display* dpy = NULL; Window dock_win = None; { int i; for (i = 1; i < argc; i++) { char* arg = argv[i]; if (strcmp(arg, "-h") == 0) { usage(); return 0; } else if (w < 0) { int t = atoi(arg); if (t <= 0) { fprintf(stderr, "error, width must be greater than 0.\n"); return EXIT_FAILURE; } w = t; } else if (h < 0) { int t = atoi(arg); if (t <= 0) { fprintf(stderr, "error, height must be greater than 0.\n"); return EXIT_FAILURE; } h = t; } } } if (w == -1) { w = 1; } if (h == -1) { h = 1; } dpy = XOpenDisplay(NULL); assert(dpy != NULL); /* create the window */ { XSizeHints size_hints; XWMHints wm_hints; XClassHint class_hint; int border_width = 1; size_hints.x = 0; size_hints.y = 0; size_hints.flags = USSize|USPosition; size_hints.width = w; size_hints.height = h; dock_win = XCreateSimpleWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), size_hints.x, size_hints.y, size_hints.width, size_hints.height, border_width, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy))); assert(dock_win != None); XSetWMNormalHints(dpy, dock_win, &size_hints); class_hint.res_name = dock_name; class_hint.res_class = dock_name; XSetClassHint(dpy, dock_win, &class_hint); XSelectInput(dpy, dock_win, ButtonPressMask|ExposureMask|ButtonReleaseMask|PointerMotionMask|StructureNotifyMask); wm_hints.initial_state = WithdrawnState; wm_hints.icon_window = None; wm_hints.window_group = dock_win; wm_hints.flags = StateHint | WindowGroupHint; XSetWMHints(dpy, dock_win, &wm_hints); XMapWindow(dpy, dock_win); } /* eventloop */ { XEvent event; for (;;) { if (XPending(dpy)) { XNextEvent(dpy, &event); switch (event.type) { case DestroyNotify: XCloseDisplay(dpy); break; } } poll(NULL, 0, 25); } } return EXIT_SUCCESS; } /* ---------------------------------------------------------------- *\ \* ---------------------------------------------------------------- */