From 51c9f2a852c1f699671a42da4348de194832efcd Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 30 Mar 2012 17:36:12 +0100 Subject: [PATCH] Also allow relaunching from appicon. Allow relaunching an application with a middle mouse click to its appicon or the Launch option of its appicon menu. --- src/appicon.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/appicon.c b/src/appicon.c index d05413bf..19f56148 100644 --- a/src/appicon.c +++ b/src/appicon.c @@ -295,6 +295,39 @@ Bool wAppIconSave(WAppIcon *aicon) #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance)) +/* main_window may not have the full command line; try to find one which does */ +static void relaunchApplication(WApplication *wapp) +{ + WScreen *scr; + WWindow *wlist, *next; + + scr = wapp->main_window_desc->screen_ptr; + wlist = scr->focused_window; + if (! wlist) + return; + + while (wlist->prev) + wlist = wlist->prev; + + while (wlist) { + next = wlist->next; + + if (wlist->main_window == wapp->main_window) { + if (RelaunchWindow(wlist)) + return; + } + + wlist = next; + } +} + +static void relaunchCallback(WMenu * menu, WMenuEntry * entry) +{ + WApplication *wapp = (WApplication *) entry->clientdata; + + relaunchApplication(wapp); +} + static void hideCallback(WMenu * menu, WMenuEntry * entry) { WApplication *wapp = (WApplication *) entry->clientdata; @@ -403,6 +436,7 @@ static WMenu *createApplicationMenu(WScreen * scr) WMenu *menu; menu = wMenuCreate(scr, NULL, False); + wMenuAddCallback(menu, _("Launch"), relaunchCallback, NULL); wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL); wMenuAddCallback(menu, _("Hide"), hideCallback, NULL); wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL); @@ -505,6 +539,16 @@ void appIconMouseDown(WObjDescriptor * desc, XEvent * event) return; } + if (event->xbutton.button == Button2) { + WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window); + + if (!wapp) + return; + + relaunchApplication(wapp); + return; + } + if (event->xbutton.button == Button3) { WObjDescriptor *desc; WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);