diff --git a/programs/dtbar/dtbar.c b/programs/dtbar/dtbar.c index 6e7ae2e2..2832b9ce 100644 --- a/programs/dtbar/dtbar.c +++ b/programs/dtbar/dtbar.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ static Widget shell, form, bar, clockLabel; static Widget sink; /* the root's and the client's events go here */ static Atom aBar, aMenu, aActive, aActivate, aRefresh, aUtf8, aManager; static Atom aNetActive, aLeader, aCommand; +static Widget forceQuitItem; static Window client; /* the window whose menus are shown */ static Boolean focused = True; /* client's program has the focus */ static McdeMenuItem items[MCDE_MENU_MAX]; @@ -279,6 +281,107 @@ ForceQuit(Widget w, XtPointer data, XtPointer call) ShowForceQuit(); } +/* a program of the session, started directly (no shell, no foreign text): + * dtsystemsettings with the pane as its one argument */ +static void +RunProgram(Widget w, XtPointer data, XtPointer call) +{ + char *argv[] = { "dtsystemsettings", "-pane", (char *) data, NULL }; + + (void) w; + (void) call; + Spawn(argv); +} + +static void +SetAccel(Widget item, const char *text) +{ + XmString s = XmStringCreateLocalized((char *) text); + + XtVaSetValues(item, XmNacceleratorText, s, NULL); + XmStringFree(s); +} + +/* the program of a window: the WM_CLASS class string, else the window name */ +static void +ProgramOf(Window w, char *buf, size_t len) +{ + XClassHint ch; + XTextProperty tp; + + buf[0] = '\0'; + if (w == None) + return; + if (XGetClassHint(dpy, w, &ch)) { + const char *name = ch.res_class != NULL && ch.res_class[0] != '\0' ? + ch.res_class : ch.res_name; + + if (name != NULL) + snprintf(buf, len, "%s", name); + if (ch.res_name != NULL) + XFree(ch.res_name); + if (ch.res_class != NULL) + XFree(ch.res_class); + } + if (buf[0] == '\0' && XGetWMName(dpy, w, &tp) && tp.value != NULL) { + snprintf(buf, len, "%.*s", (int) tp.nitems, (char *) tp.value); + XFree(tp.value); + } +} + +/* the program of the focused window (MCDE: the reference names it in the + * Force Quit item, "Force Quit Finder"). _NET_ACTIVE_WINDOW first; a window + * manager that does not set it leaves the keyboard focus, and with the bar + * focused the program whose menus it carries. */ +static void +ActiveProgram(char *buf, size_t len) +{ + Atom type; + int format; + unsigned long n, after; + unsigned char *data = NULL; + Window active = None; + int revert; + Window focus; + + buf[0] = '\0'; + if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), aNetActive, 0, 1, + False, XA_WINDOW, &type, &format, &n, &after, &data) == Success && + data != NULL && n == 1 && format == 32) + active = (Window) *(long *) data; + if (data != NULL) + XFree(data); + if (active != None) + ProgramOf(XmuClientWindow(dpy, active), buf, len); + if (buf[0] == '\0') { + XGetInputFocus(dpy, &focus, &revert); + if (focus != None && focus != PointerRoot) + ProgramOf(XmuClientWindow(dpy, focus), buf, len); + } + if (buf[0] == '\0' && client != None) + ProgramOf(XmuClientWindow(dpy, client), buf, len); +} + +/* the Force Quit item names the program when the M menu opens */ +static void +FillForceQuit(Widget w, XtPointer data, XtPointer call) +{ + char name[128], label[192]; + XmString s; + + (void) w; + (void) data; + (void) call; + ActiveProgram(name, sizeof name); + if (name[0] != '\0') + snprintf(label, sizeof label, "Force Quit %s", name); + else + snprintf(label, sizeof label, "Force Quit..."); + s = XmStringCreateLocalized(label); + XtVaSetValues(forceQuitItem, XmNlabelString, s, NULL); + XmStringFree(s); +} + /* Favourites (~/.dt/favourites, by hand) and Recent Items (~/.dt/recent, * by dtbar): items.c */ static Widget favouritesMenu, recentMenu; @@ -482,7 +585,10 @@ MakeMMenu(void) char logout[200]; Push(menu, "About This Computer", 'A', About, NULL); - Push(menu, "Software Update...", 'U', NULL, NULL); + Push(menu, "Software Update...", 'U', RunProgram, "update"); + /* the package catalogue is a task of its own (t0056): insensitive + * until it exists, as the reference's "Mac OS X Software..." */ + Push(menu, "Makronix Software...", 'w', NULL, NULL); Separator(menu); Push(menu, "System Settings...", 'S', RunAction, "dtsystemsettings"); Separator(menu); @@ -495,7 +601,21 @@ MakeMMenu(void) XtAddCallback(menu, XmNmapCallback, FillFavourites, NULL); XtAddCallback(menu, XmNmapCallback, FillRecent, NULL); Separator(menu); - Push(menu, "Force Quit...", 'Q', ForceQuit, NULL); + forceQuitItem = Push(menu, "Force Quit...", 'Q', ForceQuit, NULL); + SetAccel(forceQuitItem, "Cmd+Option+Esc"); + XtAddCallback(menu, XmNmapCallback, FillForceQuit, NULL); + Separator(menu); + { + Widget panelMenu = Pulldown(menu, "frontPanel"); + Widget item; + + (void) Cascade(menu, "Front Panel", 'F', panelMenu); + item = Push(panelMenu, "Show or Hide", 'H', MAction, + "f.toggle_frontpanel"); + SetAccel(item, "Cmd+Option+D"); + /* the pane of the bar comes with t0112 */ + Push(panelMenu, "Settings...", 'E', NULL, NULL); + } Separator(menu); Push(menu, "Sleep", 'l', DoPower, (XtPointer) (size_t) MCDE_POWER_SLEEP); Push(menu, "Restart...", 't', AskPower, @@ -505,7 +625,11 @@ MakeMMenu(void) Separator(menu); Push(menu, "Lock Screen", 'k', MAction, "LockDisplay"); LogOutLabel(logout, sizeof logout); - Push(menu, logout, 'O', MAction, "ExitSession"); + { + Widget item = Push(menu, logout, 'O', MAction, "ExitSession"); + + SetAccel(item, "Shift+Cmd+Q"); + } /* the Makronix logo, 16 pixels (icons/MakronixDtlogo.t.pm), given when * the button is made so that Motif sizes it; the letter M where the * icon is missing (the resource mcdeM.labelString) */