forked from e16/e16
1
0
Fork 0

Defer menu loading. Unload 5 min after last use.

SVN revision: 16923
This commit is contained in:
Kim Woelders 2005-09-25 00:50:53 +00:00
parent ccb844716d
commit 75a5b77287
14 changed files with 428 additions and 507 deletions

View File

@ -69,7 +69,7 @@ __ACLASS __BGN
__TOOLTIP_ACTION_TEXT "Show the Window Options menu."
__EVENT __MOUSE_PRESS
__BUTTON 3
__ACTION __A_SHOW_MENU "named WINOPS_MENU"
__ACTION __A_SHOW_MENU "WINOPS_MENU"
__NEXT_ACTION
__TOOLTIP_ACTION_TEXT "Toggle the shaded (rolled-up) state of this window."
__EVENT __DOUBLE_CLICK
@ -275,7 +275,7 @@ __ACLASS __BGN
__ALLOW_ANY_MODIFIER_KEYS __ON
__EVENT __MOUSE_PRESS
__ALLOW_ANY_BUTTON __ON
__ACTION __A_SHOW_MENU "named WINOPS_MENU"
__ACTION __A_SHOW_MENU "WINOPS_MENU"
__END
@ -292,7 +292,7 @@ __ACLASS __BGN
__TOOLTIP_ACTION_TEXT "Open the Window Options Menu."
__EVENT __MOUSE_PRESS
__BUTTON 3
__ACTION __A_SHOW_MENU "named WINOPS_MENU"
__ACTION __A_SHOW_MENU "WINOPS_MENU"
__END
__ACLASS __BGN

View File

@ -39,28 +39,28 @@ MouseDown AS 1 wop * swapmove
MouseDouble A 1 wop * shade
MouseDown A 2 wop * sz ptr
MouseDouble A 2 wop * th available
MouseDown A 3 menus show named WINOPS_MENU
MouseDown A 3 menus show WINOPS_MENU
# Mouse presses on the desktop background ....
Aclass DESKBINDINGS normal
Tooltip Clicking your mouse on the desktop will perform
Tooltip the following actions
MouseDown - 1 menus show named APPS_SUBMENU
MouseDown - 1 menus show APPS_SUBMENU
Tooltip Display User Menus
MouseDown C 1 menus show named ROOT_2
MouseDown C 1 menus show ROOT_2
Tooltip Display Enlightenment Menu
MouseDown 4 1 menus show named CONFIG_SUBMENU
MouseDown 4 1 menus show CONFIG_SUBMENU
Tooltip Display Settings Menu
MouseDown - 2 menus show named ROOT_2
MouseDown - 2 menus show ROOT_2
Tooltip Display Enlightenment Menu
MouseDown A 2 menus show taskmenu
MouseDown A 2 menus show windowlist
Tooltip Display Task List Menu
MouseDown C 2 menus show deskmenu
Tooltip Display Desktop Menu
MouseDown S 2 menus show groupmenu
Tooltip Display Group Menu
MouseDown - 3 menus show named CONFIG_SUBMENU
MouseDown - 3 menus show CONFIG_SUBMENU
Tooltip Display Settings Menu
MouseDown * 4 desk prev
Tooltip Go Back a Desktop
@ -104,12 +104,12 @@ KeyDown CA i wop * iconify
KeyDown CA r wop * shade
KeyDown CA f wop * fullscreen
KeyDown CA m wop * ts conservative
KeyDown CA w menus show named WINOPS_MENU
KeyDown CA w menus show WINOPS_MENU
KeyDown A Return wop * zoom
KeyDown CS F1 menus show named APPS_SUBMENU
KeyDown CS F2 menus show named ROOT_2
KeyDown CS F3 menus show named CONFIG_SUBMENU
KeyDown CS F4 menus show taskmenu
KeyDown CS F1 menus show APPS_SUBMENU
KeyDown CS F2 menus show ROOT_2
KeyDown CS F3 menus show CONFIG_SUBMENU
KeyDown CS F4 menus show windowlist
# These keybindings cant be edited because they arent called "KEYBINDINGS" thus

View File

@ -22,7 +22,7 @@ ADD_MENU_TEXT_ITEM("Create Systray", __A_CMD, "ibox new _ST_")
END_MENU
BEGIN_NEW_MENU("MAINT_SUBMENU", "ROOT")
ADD_MENU_TITLE("Enlightenment Maintenance")
ADD_MENU_TITLE("Maintenance")
ADD_MENU_TEXT_ITEM("Purge config file cache", __A_EXEC, E_SCRIPTS_DIR"e_cache_clean config")
ADD_MENU_TEXT_ITEM("Purge pager background cache", __A_EXEC, E_SCRIPTS_DIR"e_cache_clean pager")
ADD_MENU_TEXT_ITEM("Purge background selector cache", __A_EXEC, E_SCRIPTS_DIR"e_cache_clean bgsel")
@ -36,16 +36,13 @@ END_MENU
/* dont need this anymore - will have a scritp soon to do it all
BEGIN_NEW_GNOME_MENU("GNOME_SUBMENU", "ROOT", "/usr/share/gnome/apps")
ADD_MENU_TITLE("Gnome Apps")
END_MENU
BEGIN_NEW_GNOME_MENU("GNOME_USER_SUBMENU", "ROOT", HOME_DIR"/.gnome/apps")
ADD_MENU_TITLE("Gnome Apps")
END_MENU
*/
BEGIN_NEW_THEMES_MENU("THEMES_SUBMENU", "ROOT")
ADD_MENU_TITLE("Themes")
END_MENU
BEGIN_NEW_MENU("CONFIG_SUBMENU", "ROOT")

View File

@ -74,11 +74,14 @@ _("Display Settings Menu"),
_("Go Back a Desktop"),
_("Go Forward a Desktop"),
/* menus.cfg */
_("Backgrounds"),
_("Desktop Operations"),
_("Cleanup Desktop"),
_("Goto Next Desktop"),
_("Goto Previous Desktop"),
_("Create New Iconbox"),
_("Create Systray"),
_("Maintenance"),
_("Purge config file cache"),
_("Purge pager background cache"),
_("Purge background selector cache"),
@ -88,6 +91,7 @@ _("Query pager background cache usage"),
_("Query background selector cache usage"),
_("Query all cache usage"),
_("Regenerate Menus"),
_("Settings"),
_("Focus Settings ..."),
_("Move & Resize Settings ..."),
_("Pager Settings ..."),
@ -105,6 +109,7 @@ _("Desktop Background Settings ..."),
_("Theme Transparency Settings ..."),
_("Composite Settings ..."),
_("Miscellaneous Settings ..."),
_("Enlightenment"),
_("Help"),
_("About Enlightenment"),
_("About this theme"),
@ -133,8 +138,11 @@ _("100%"),
_("Toggle Shadows"),
_("Toggle Skip Window Lists"),
_("Toggle Fixed Position"),
_("Toggle Fixed Size"),
_("Toggle Never Focus"),
_("Toggle Click to Focus"),
_("Toggle Never Use Area"),
_("Toggle Button Grabs"),
_("Configure this window's group(s)"),
_("Start a new group"),
_("Select group to add this window to"),

View File

@ -52,7 +52,11 @@ sub x() {
}
# menus.cfg
if (/ADD_MENU_TEXT_ITEM\s*\(\s*(\".*\"),/) {
if (/ADD_MENU_TITLE\s*\(\s*(\".*\")/) {
$t = "$1";
print "_($t),\n";
}
elsif (/ADD_MENU_TEXT_ITEM\s*\(\s*(\".*\"),/) {
$t = "$1";
print "_($t),\n";
}

View File

@ -1472,6 +1472,7 @@ void ITApply(Window win, ImageClass * ic, ImageState * is, int w,
void __PRINTF__ IpcPrintf(const char *fmt, ...);
int HandleIPC(const char *params, Client * c);
int EFunc(EWin * ewin, const char *params);
void EFuncDefer(EWin * ewin, const char *params);
/* lang.c */
void LangInit(void);

View File

@ -198,7 +198,6 @@ ConfigAlertLoad(const char *txt)
static int
ConfigFilePreparse(const char *path, const char *dest)
{
static char have_epp = 0;
char execline[FILEPATH_LEN_MAX];
const char *epp_path = ENLIGHTENMENT_BIN "/epp";
char *def_home, *def_user, *def_shell;
@ -206,17 +205,6 @@ ConfigFilePreparse(const char *path, const char *dest)
if (EventDebug(EDBUG_TYPE_CONFIG))
Eprintf("ConfigFilePreparse %s->%s\n", path, dest);
if ((!have_epp) && (!(isfile(epp_path)) && (canexec(epp_path))))
{
Alert(_("Help! Cannot find epp!\n"
"Enlightenment is looking for epp here:\n" "%s\n"
"This is a FATAL ERROR.\n"
"This is probably due to either the program not existing or\n"
"it not being able to be executed by you.\n"), epp_path);
SessionExit(EEXIT_ERROR, NULL);
}
have_epp = 1;
def_home = homedir(getuid());
def_user = username(getuid());
def_shell = usershell(getuid());
@ -409,7 +397,7 @@ FindFileLocalized(const char *name, const char *path, int localized)
lang = Mode.locale.lang;
if (!localized || !lang)
{
if (isfile(s))
if (isfile(s) && canread(s)) /* FIXME - Only one stat */
return Estrdup(s);
else
return NULL;
@ -432,7 +420,7 @@ FindFileLocalized(const char *name, const char *path, int localized)
continue;
*p[i] = '\0';
if (isfile(s))
if (isfile(s) && canread(s)) /* FIXME - Only one stat */
return Estrdup(s);
}

View File

@ -104,7 +104,7 @@ DeskControlsCreate(Desk * dsk)
a = ActionCreate(EVENT_MOUSE_DOWN, 0, 0, 0, 2, 0, NULL, NULL);
ActionclassAddAction(ac, a);
ActionAddTo(a, "menus show taskmenu");
ActionAddTo(a, "menus show windowlist");
if (dsk->num > 0)
{

View File

@ -215,6 +215,8 @@ struct _ewin
#define EWIN_TYPE_ICONBOX 0x04
#define EWIN_TYPE_PAGER 0x08
#define EwinGetDesk(ewin) EoGetDesk(ewin)
#define EwinIsMapped(ewin) (ewin->state.state >= EWIN_STATE_MAPPED)
#define EwinIsInternal(ewin) (ewin->type != EWIN_TYPE_NORMAL)
#define EwinIsTransientChild(ewin) (ewin->icccm.transient > 0)

View File

@ -1576,6 +1576,39 @@ EFunc(EWin * ewin, const char *params)
return err;
}
static void
doEFuncDeferred(int val __UNUSED__, void *data)
{
void **prm = (void **)data;
EWin *ewin;
ewin = prm[0];
if (ewin && !EwinFindByPtr(ewin))
return;
EFunc(ewin, prm[1]);
Efree(prm[1]);
Efree(data);
}
void
EFuncDefer(EWin * ewin, const char *cmd)
{
static int seqn = 0;
char s[32];
void **prm;
prm = Emalloc(2 * sizeof(void *));
if (!prm)
return;
prm[0] = ewin;
prm[1] = Estrdup(cmd);
Esnprintf(s, sizeof(s), "EFunc-%d", seqn++);
DoIn(s, 0.0, doEFuncDeferred, 0, prm);
}
static int
ipccmp(void *p1, void *p2)
{

View File

@ -30,6 +30,11 @@
#include <errno.h>
#include <sys/stat.h>
static Menu *MenuCreateFromFlatFile(const char *name, Menu * parent,
MenuStyle * ms, const char *file);
static Menu *MenuCreateFromDirectory(const char *name, Menu * parent,
MenuStyle * ms, const char *dir);
static MenuItem *
MenuItemCreateFromBackground(const char *bgid, const char *file)
{
@ -51,13 +56,13 @@ MenuItemCreateFromBackground(const char *bgid, const char *file)
return mi;
}
Menu *
MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
const char *dir)
static int
MenuLoadFromDirectory(Menu * m)
{
Progressbar *p = NULL;
Menu *m, *mm;
Menu *mm;
int i, num;
const char *dir;
char **list, s[4096], ss[4096], cs[4096];
const char *ext;
MenuItem *mi;
@ -65,8 +70,15 @@ MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
const char *chmap =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
FILE *f;
time_t lastmod;
m = MenuCreate(name, NULL, parent, ms);
dir = MenuGetData(m);
lastmod = moddate(dir);
if (lastmod <= MenuGetTimestamp(m))
return 0;
MenuSetTimestamp(m, lastmod);
MenuEmpty(m, 0);
if (stat(dir, &st) >= 0)
{
@ -122,15 +134,16 @@ MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
char tmp[4096];
word(s, 2, tmp);
Esnprintf(s, sizeof(s), "%s/%s:%s", dir, tmp, name);
Esnprintf(s, sizeof(s), "%s/%s:%s", dir, tmp,
MenuGetName(m));
Esnprintf(ss, sizeof(ss), "%s/%s", dir, tmp);
mm = MenuCreateFromDirectory(s, m, ms, ss);
mm = MenuCreateFromDirectory(s, m, NULL, ss);
mi = MenuItemCreate(tmp, NULL, NULL, mm);
MenuAddItem(m, mi);
}
}
fclose(f);
return m;
return 1;
}
}
@ -156,8 +169,8 @@ MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
ext = FileExtension(ss);
if (S_ISDIR(st.st_mode))
{
Esnprintf(s, sizeof(s), "%s/%s:%s", dir, list[i], name);
mm = MenuCreateFromDirectory(s, m, ms, ss);
Esnprintf(s, sizeof(s), "%s/%s:%s", dir, list[i], MenuGetName(m));
mm = MenuCreateFromDirectory(s, m, NULL, ss);
mi = MenuItemCreate(list[i], NULL, NULL, mm);
MenuAddItem(m, mi);
if (f)
@ -229,6 +242,26 @@ MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
if (list)
StrlistFree(list, num);
return 1;
}
static Menu *
MenuCreateFromDirectory(const char *name, Menu * parent, MenuStyle * ms,
const char *dir)
{
static int calls = 0;
Menu *m;
if (calls > 32)
return NULL;
calls++;
m = MenuCreate(name, NULL, parent, ms);
MenuSetData(m, Estrdup(dir));
MenuSetLoader(m, MenuLoadFromDirectory);
calls--;
return m;
}
@ -238,6 +271,7 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
FILE *f;
char first = 1;
char s[4096];
int count;
f = fopen(file, "r");
if (!f)
@ -247,6 +281,7 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
return;
}
count = 0;
while (fgets(s, 4096, f))
{
s[strlen(s) - 1] = 0;
@ -272,7 +307,6 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
MenuItem *mi;
ImageClass *icc = NULL;
Menu *mm;
static int count = 0;
txt = field(s, 0);
icon = field(s, 1);
@ -300,8 +334,7 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
}
else if ((act) && (!strcmp(act, "menu")) && (params))
{
Esnprintf(wd, sizeof(wd), "__FM.%s.%i", name, count);
count++;
Esnprintf(wd, sizeof(wd), "__FM.%s.%i", name, count++);
mm = MenuCreateFromFlatFile(wd, m, NULL, params);
if (mm)
{
@ -328,53 +361,30 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
fclose(f);
}
static void
FileMenuUpdate(int val __UNUSED__, void *data)
static int
MenuLoadFromFlatFile(Menu * m)
{
Menu *m;
time_t lastmod;
char s[4096];
const char *ff;
m = (Menu *) data;
if (!m)
return;
if (!FindItem(m, 0, LIST_FINDBY_POINTER, LIST_TYPE_MENU))
return;
/* if the menu is up dont update */
if (MenusActive())
goto done;
time_t lastmod;
ff = MenuGetData(m);
if (!exists(ff))
{
MenuHide(m);
MenuEmpty(m);
return;
}
lastmod = moddate(ff);
if (lastmod > MenuGetTimestamp(m))
{
MenuSetTimestamp(m, lastmod);
MenuEmpty(m);
FillFlatFileMenu(m, MenuGetName(m), ff);
MenuRepack(m);
}
if (lastmod <= MenuGetTimestamp(m))
return 0;
MenuSetTimestamp(m, lastmod);
done:
Esnprintf(s, sizeof(s), "__.%s", MenuGetName(m));
DoIn(s, 5.0, FileMenuUpdate, 0, m);
MenuEmpty(m, 0);
FillFlatFileMenu(m, MenuGetName(m), ff);
return 1;
}
Menu *
static Menu *
MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms,
const char *file)
{
Menu *m = NULL;
char s[4096], *ff;
char *ff;
static int calls = 0;
if (calls > 32)
@ -385,17 +395,9 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms,
if (!ff)
goto done;
if (canread(ff))
{
m = MenuCreate(name, NULL, parent, ms);
MenuSetTimestamp(m, moddate(ff));
FillFlatFileMenu(m, MenuGetName(m), ff);
MenuSetData(m, ff);
Esnprintf(s, sizeof(s), "__.%s", MenuGetName(m));
DoIn(s, 5.0, FileMenuUpdate, 0, m);
goto done;
}
Efree(ff);
m = MenuCreate(name, NULL, parent, ms);
MenuSetData(m, ff);
MenuSetLoader(m, MenuLoadFromFlatFile);
done:
calls--;
@ -403,7 +405,7 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms,
return m;
}
Menu *
static Menu *
MenuCreateFromGnome(const char *name, Menu * parent, MenuStyle * ms,
const char *dir)
{
@ -520,23 +522,23 @@ MenuCreateFromGnome(const char *name, Menu * parent, MenuStyle * ms,
return m;
}
Menu *
MenuCreateFromThemes(const char *name, MenuStyle * ms)
static int
MenuLoadFromThemes(Menu * m)
{
Menu *m;
char **lst;
int i, num;
char ss[4096], *s;
MenuItem *mi;
m = MenuCreate(name, NULL, NULL, ms);
if (MenuGetTimestamp(m))
return 0;
MenuSetTimestamp(m, 1);
lst = ThemesList(&num);
for (i = 0; i < num; i++)
{
s = fullfileof(lst[i]);
Esnprintf(ss, sizeof(ss), "themes use %s", s);
Esnprintf(ss, sizeof(ss), "theme use %s", s);
mi = MenuItemCreate(s, NULL, ss, NULL);
Efree(s);
MenuAddItem(m, mi);
@ -544,6 +546,19 @@ MenuCreateFromThemes(const char *name, MenuStyle * ms)
if (lst)
StrlistFree(lst, i);
return 1;
}
static Menu *
MenuCreateFromThemes(const char *name, MenuStyle * ms)
{
Menu *m;
m = MenuCreate(name, NULL, NULL, ms);
MenuSetTitle(m, _("Themes"));
MenuSetInternal(m);
MenuSetLoader(m, MenuLoadFromThemes);
return m;
}
@ -556,7 +571,7 @@ BorderNameCompare(void *b1, void *b2)
return 0;
}
Menu *
static Menu *
MenuCreateFromBorders(const char *name, MenuStyle * ms)
{
char s[128];
@ -586,97 +601,153 @@ MenuCreateFromBorders(const char *name, MenuStyle * ms)
return m;
}
Menu *
MenuCreateFromAllEWins(const char *name, MenuStyle * ms)
static int
MenuCheckShowEwinDesk(EWin * ewin, void *prm)
{
if (!EwinGetName(ewin) || ewin->props.skip_winlist)
return 0;
return prm == NULL || EwinGetDesk(ewin) == prm;
}
static void
MenuLoadFromEwins(Menu * m, int (*f) (EWin * ewin, void *prm), void *prm)
{
Menu *m;
EWin *const *lst;
int i, num;
char s[256];
MenuItem *mi;
m = MenuCreate(name, NULL, NULL, ms);
lst = EwinListGetAll(&num);
for (i = 0; i < num; i++)
{
if (lst[i]->props.skip_winlist || !EwinGetName(lst[i]))
if (!f(lst[i], prm))
continue;
Esnprintf(s, sizeof(s), "wop %#lx focus", _EwinGetClientXwin(lst[i]));
mi = MenuItemCreate(EwinGetName(lst[i]), NULL, s, NULL);
MenuAddItem(m, mi);
}
return m;
}
#if 0 /* Not used */
static int
MenuLoadFromAllEwins(Menu * m)
{
MenuEmpty(m, 0);
MenuLoadFromEwins(m, MenuCheckShowEwinDesk, NULL);
return 1;
}
static Menu *
MenuCreateFromDesktopEWins(char *name, Menu * parent, MenuStyle * ms, int desk)
MenuCreateFromAllEWins(const char *name, MenuStyle * ms)
{
Menu *m;
EWin *const *lst;
int i, num;
char s[256];
MenuItem *mi;
m = MenuCreate(name, NULL, parent, ms);
lst = EwinListGetAll(&num);
for (i = 0; i < num; i++)
{
if (lst[i]->props.skip_winlist || !EwinGetName(lst[i]) ||
EoGetDesk(lst[i]) != j)
continue;
Esnprintf(s, sizeof(s), "%lu", _EwinGetClientXwin(lst[i]));
mi = MenuItemCreate(lst[i]->client.title, NULL, s, NULL);
MenuAddItem(m, mi);
}
m = MenuCreate(name, NULL, NULL, ms);
MenuSetTitle(m, _("Window List"));
MenuSetInternal(m);
MenuSetDynamic(m);
MenuSetLoader(m, MenuLoadFromAllEwins);
return m;
}
#endif
Menu *
MenuCreateFromDesktops(const char *name, MenuStyle * ms)
static int
MenuLoadFromDesktops(Menu * m)
{
Menu *m, *mm;
EWin *const *lst;
int i, num;
unsigned int j;
Menu *mm;
unsigned int i;
char s[256];
MenuItem *mi;
m = MenuCreate(name, NULL, NULL, ms);
MenuEmpty(m, 0);
lst = EwinListGetAll(&num);
for (j = 0; j < DesksGetNumber(); j++)
for (i = 0; i < DesksGetNumber(); i++)
{
mm = MenuCreate("__SUBMENUDESK_E", NULL, m, ms);
Esnprintf(s, sizeof(s), "desk goto %i", j);
mm = MenuCreate("__SUBMENUDESK_E", NULL, m, NULL);
Esnprintf(s, sizeof(s), "desk goto %i", i);
mi = MenuItemCreate(_("Go to this Desktop"), NULL, s, NULL);
MenuAddItem(mm, mi);
for (i = 0; i < num; i++)
{
if (lst[i]->props.skip_winlist || !EwinGetName(lst[i]) ||
EoGetDesk(lst[i]) != DeskGet(j))
continue;
MenuLoadFromEwins(mm, MenuCheckShowEwinDesk, DeskGet(i));
Esnprintf(s, sizeof(s), "wop %#lx focus",
_EwinGetClientXwin(lst[i]));
mi = MenuItemCreate(EwinGetName(lst[i]), NULL, s, NULL);
MenuAddItem(mm, mi);
}
Esnprintf(s, sizeof(s), _("Desktop %i"), j);
Esnprintf(s, sizeof(s), _("Desktop %i"), i);
mi = MenuItemCreate(s, NULL, NULL, mm);
MenuAddItem(m, mi);
}
return 1;
}
static Menu *
MenuCreateFromDesktops(const char *name, MenuStyle * ms)
{
Menu *m;
m = MenuCreate(name, NULL, NULL, ms);
MenuSetTitle(m, _("Desks"));
MenuSetInternal(m);
MenuSetDynamic(m);
MenuSetLoader(m, MenuLoadFromDesktops);
return m;
}
static int
MenuLoadFromGroups(Menu * m)
{
Menu *mm;
Group **lst;
int i, j, num;
char s[256];
MenuItem *mi;
MenuEmpty(m, 0);
lst = (Group **) ListItemType(&num, LIST_TYPE_GROUP);
if (!lst)
return 1;
for (i = 0; i < num; i++)
{
mm = MenuCreate("__SUBMENUGROUP_E", NULL, m, NULL);
Esnprintf(s, sizeof(s), "gop %li showhide",
_EwinGetClientXwin(lst[i]->members[0]));
mi = MenuItemCreate(_("Show/Hide this group"), NULL, s, NULL);
Esnprintf(s, sizeof(s), "wop %#lx ic",
_EwinGetClientXwin(lst[i]->members[0]));
MenuAddItem(mm, mi);
mi = MenuItemCreate(_("Iconify this group"), NULL, s, NULL);
MenuAddItem(mm, mi);
for (j = 0; j < lst[i]->num_members; j++)
{
Esnprintf(s, sizeof(s), "wop %#lx focus",
_EwinGetClientXwin(lst[i]->members[j]));
mi = MenuItemCreate(EwinGetName(lst[i]->members[j]), NULL,
s, NULL);
MenuAddItem(mm, mi);
}
Esnprintf(s, sizeof(s), _("Group %i"), i);
mi = MenuItemCreate(s, NULL, NULL, mm);
MenuAddItem(m, mi);
}
Efree(lst);
return 1;
}
static Menu *
MenuCreateFromGroups(const char *name, MenuStyle * ms)
{
Menu *m;
m = MenuCreate(name, NULL, NULL, ms);
MenuSetTitle(m, _("Groups"));
MenuSetInternal(m);
MenuSetDynamic(m);
MenuSetLoader(m, MenuLoadFromGroups);
return m;
}
@ -704,129 +775,51 @@ MenuCreateMoveToDesktop(char *name, Menu * parent, MenuStyle * ms)
}
#endif
static Menu *
MenuCreateFromGroups(const char *name, MenuStyle * ms)
Menu *
MenusCreateInternal(const char *type, const char *name, const char *style,
const char *prm)
{
Menu *m, *mm;
Group **lst;
int i, j, num;
char s[256];
Menu *m;
MenuStyle *ms;
MenuItem *mi;
m = NULL;
ms = NULL;
if (style)
ms = FindItem(style, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
m = MenuCreate(name, NULL, NULL, ms);
lst = (Group **) ListItemType(&num, LIST_TYPE_GROUP);
if (lst)
if (!strcmp(type, "file"))
{
for (i = 0; i < num; i++)
{
mm = MenuCreate("__SUBMENUGROUP_E", NULL, m, ms);
Esnprintf(s, sizeof(s), "gop %li showhide",
_EwinGetClientXwin(lst[i]->members[0]));
mi = MenuItemCreate(_("Show/Hide this group"), NULL, s, NULL);
Esnprintf(s, sizeof(s), "wop %#lx ic",
_EwinGetClientXwin(lst[i]->members[0]));
MenuAddItem(mm, mi);
mi = MenuItemCreate(_("Iconify this group"), NULL, s, NULL);
MenuAddItem(mm, mi);
for (j = 0; j < lst[i]->num_members; j++)
{
Esnprintf(s, sizeof(s), "wop %#lx focus",
_EwinGetClientXwin(lst[i]->members[j]));
mi = MenuItemCreate(EwinGetName(lst[i]->members[j]), NULL,
s, NULL);
MenuAddItem(mm, mi);
}
Esnprintf(s, sizeof(s), _("Group %i"), i);
mi = MenuItemCreate(s, NULL, NULL, mm);
MenuAddItem(m, mi);
}
Efree(lst);
m = MenuCreateFromFlatFile(name, NULL, ms, prm);
}
else if (!strcmp(type, "dirscan"))
{
SoundPlay("SOUND_SCANNING");
m = MenuCreateFromDirectory(name, NULL, ms, prm);
}
else if (!strcmp(type, "gnome"))
{
m = MenuCreateFromGnome(name, NULL, ms, prm);
}
else if (!strcmp(type, "borders"))
{
m = MenuCreateFromBorders(name, ms);
}
else if (!strcmp(type, "themes"))
{
m = MenuCreateFromThemes(name, ms);
}
else if (!strcmp(type, "windowlist"))
{
m = MenuCreateFromAllEWins(name, ms);
}
else if (!strcmp(type, "deskmenu"))
{
m = MenuCreateFromDesktops(name, ms);
}
else if (!strcmp(type, "groupmenu"))
{
m = MenuCreateFromGroups(name, ms);
}
return m;
}
#if 0 /* Not used */
static Menu *
RefreshTaskMenu(int desk)
{
char was = 0;
int lx = 0, ly = 0;
EWin *ewin;
if (task_menu[desk])
{
ewin = FindEwinByMenu(task_menu[desk]);
if ((task_menu[desk]->win) && (ewin))
{
lx = ewin->x;
ly = ewin->y;
was = 1;
}
MenuDestroy(task_menu[desk]);
}
task_menu[desk] = NULL;
if (!task_menu_style)
{
return NULL;
}
task_menu[desk] = MenuCreateFromDesktopEWins("MENU", task_menu_style, desk);
if ((was) && (task_menu[desk]))
{
task_menu[desk]->internal = 1;
MenuShow(task_menu[desk], 1);
ewin = FindEwinByMenu(task_menu[desk]);
if (ewin)
{
EwinMove(ewin, lx, ly);
ShowEwin(ewin);
}
Mode.cur_menu[0] = task_menu[desk];
Mode.cur_menu_depth = 1;
MenuShowMasker(task_menu[desk]);
}
return task_menu[desk];
}
void
ShowTaskMenu(void)
{
}
#endif
/* FIXME - Menus should have update function? */
void ShowAllTaskMenu(void);
void ShowDeskMenu(void);
void ShowGroupMenu(void);
void
ShowAllTaskMenu(void)
{
static MenuStyle *ms = NULL;
static Menu *m = NULL;
ShowInternalMenu(&m, &ms, "TASK_MENU", MenuCreateFromAllEWins);
}
void
ShowDeskMenu(void)
{
static MenuStyle *ms = NULL;
static Menu *m = NULL;
ShowInternalMenu(&m, &ms, "DESK_MENU", MenuCreateFromDesktops);
}
void
ShowGroupMenu(void)
{
static MenuStyle *ms = NULL;
static Menu *m = NULL;
ShowInternalMenu(&m, &ms, "GROUP_MENU", MenuCreateFromGroups);
}

View File

@ -28,6 +28,7 @@
#include "menus.h"
#include "tooltips.h"
#include "xwin.h"
#include <time.h>
#include <X11/keysym.h>
#define DEBUG_MENU_EVENTS 0
@ -78,22 +79,26 @@ struct _menuitem
struct _menu
{
char *name;
char *alias;
char *title;
MenuStyle *style;
MenuLoader *loader;
EWin *ewin;
int w, h;
int num;
MenuItem **items;
Window win;
PmapMask pmm;
char internal; /* Don't destroy when reloading */
char dynamic; /* May be emptied on close */
char shown;
char stuck;
char internal; /* Don't destroy when reloading */
char redraw;
Menu *parent;
Menu *child;
MenuItem *sel_item;
time_t last_change;
time_t last_access;
void *data;
unsigned int ref_count;
};
@ -166,7 +171,10 @@ MenuHide(Menu * m)
m->stuck = 0;
m->shown = 0;
m->parent = NULL;
m->last_access = time(0);
MenuHideChildren(m);
if (m->dynamic)
MenuEmpty(m, 0);
}
static void
@ -235,13 +243,16 @@ MenuShow(Menu * m, char noshow)
int w, h, mw, mh; /* from appearing offscreen */
int head_num = 0;
if ((m->num <= 0) || (!m->style))
if (m->shown || !m->style)
return;
if (m->shown)
return;
if (m->loader)
{
if (m->loader(m))
MenuRealize(m);
}
if (m->stuck)
if (m->num <= 0)
return;
if (!m->win)
@ -341,10 +352,10 @@ MenuShow(Menu * m, char noshow)
}
m->stuck = 0;
m->shown = 1;
m->last_access = time(0);
Mode_menus.just_shown = 1;
m->shown = 1;
if (!Mode_menus.first)
{
Mode_menus.context_ewin = GetContextEwin();
@ -401,16 +412,31 @@ MenuItemCreate(const char *text, ImageClass * iclass,
return mi;
}
void
MenuSetInternal(Menu * m)
{
m->internal = 1;
}
void
MenuSetDynamic(Menu * m)
{
m->dynamic = 1;
}
void
MenuSetName(Menu * m, const char *name)
{
if (m->name)
Efree(m->name);
m->name = Estrdup(name);
_EFDUP(m->name, name);
AddItem(m, m->name, 0, LIST_TYPE_MENU);
}
void
MenuSetAlias(Menu * m, const char *alias)
{
_EFDUP(m->alias, alias);
}
void
MenuSetTitle(Menu * m, const char *title)
{
@ -425,6 +451,12 @@ MenuSetData(Menu * m, char *data)
m->data = data;
}
void
MenuSetLoader(Menu * m, MenuLoader * loader)
{
m->loader = loader;
}
void
MenuSetTimestamp(Menu * m, time_t t)
{
@ -463,12 +495,6 @@ MenuSetStyle(Menu * m, MenuStyle * ms)
ms->ref_count++;
}
int
MenuIsNotEmpty(const Menu * m)
{
return m && (m->num > 0) && m->style;
}
Menu *
MenuCreate(const char *name, const char *title, Menu * parent, MenuStyle * ms)
{
@ -489,9 +515,10 @@ MenuCreate(const char *name, const char *title, Menu * parent, MenuStyle * ms)
void
MenuDestroy(Menu * m)
{
int i, j;
char s[4096];
if (!m)
return;
m = RemoveItemByPtr(m, LIST_TYPE_MENU);
if (!m)
return;
@ -500,39 +527,14 @@ MenuDestroy(Menu * m)
if (m->win)
EDestroyWindow(m->win);
Esnprintf(s, sizeof(s), "__.%s", m->name);
RemoveTimerEvent(s);
RemoveItemByPtr(m, LIST_TYPE_MENU);
MenuEmpty(m, 1);
if (m->name)
Efree(m->name);
if (m->alias)
Efree(m->alias);
if (m->title)
Efree(m->title);
for (i = 0; i < m->num; i++)
{
if (m->items[i])
{
if (m->items[i]->child)
{
if (FindItem(m->items[i]->child, 0, LIST_FINDBY_POINTER,
LIST_TYPE_MENU))
MenuDestroy(m->items[i]->child);
}
if (m->items[i]->text)
Efree(m->items[i]->text);
if (m->items[i]->params)
Efree(m->items[i]->params);
for (j = 0; j < 3; j++)
FreePmapMask(&(m->items[i]->pmm[j]));
if (m->items[i]->icon_iclass)
m->items[i]->icon_iclass->ref_count--;
if (m->items[i])
Efree(m->items[i]);
}
}
if (m->items)
Efree(m->items);
if (m->data)
Efree(m->data);
FreePmapMask(&m->pmm);
@ -546,7 +548,7 @@ MenuDestroy(Menu * m)
* imageclasses to knw to free them when not used
*/
void
MenuEmpty(Menu * m)
MenuEmpty(Menu * m, int destroying)
{
int i, j;
@ -562,8 +564,10 @@ MenuEmpty(Menu * m)
Efree(m->items[i]->params);
for (j = 0; j < 3; j++)
FreePmapMask(&(m->items[i]->pmm[j]));
if (m->items[i]->win)
if (!destroying && m->items[i]->win)
EDestroyWindow(m->items[i]->win);
if (m->items[i]->icon_iclass)
m->items[i]->icon_iclass->ref_count--;
if (m->items[i])
Efree(m->items[i]);
}
@ -622,11 +626,8 @@ MenuRealize(Menu * m)
{
m->win = ECreateWindow(VRoot.win, 0, 0, 1, 1, 0);
EventCallbackRegister(m->win, 0, MenuHandleEvents, m);
}
if (m->title)
{
HintsSetWindowName(m->win, _(m->title));
if (m->title)
HintsSetWindowName(m->win, _(m->title));
}
maxh = maxw = 0;
@ -993,46 +994,27 @@ MenusDestroyLoaded(void)
while (found_one);
}
/*
* Internal menus
*/
static Menu *
RefreshInternalMenu(Menu * m, MenuStyle * ms,
Menu * (mcf) (const char *xxx, MenuStyle * ms))
MenuFind(const char *name)
{
char was = 0;
int lx = 0, ly = 0;
EWin *ewin;
Menu *m, **lst;
int i, num;
if (m)
lst = (Menu **) ListItemType(&num, LIST_TYPE_MENU);
for (i = 0; i < num; i++)
{
ewin = m->ewin;
if ((m->win) && (ewin))
{
lx = EoGetX(ewin);
ly = EoGetY(ewin);
was = 1;
}
MenuDestroy(m);
m = NULL;
m = lst[i];
if ((m->name && !strcmp(name, m->name)) ||
(m->alias && !strcmp(name, m->alias)))
goto done;
}
if (!ms)
return NULL;
/* Not in list - try if we can load internal */
m = MenusCreateInternal(name, name, NULL, NULL);
m = mcf("MENU", ms);
if ((was) && (m))
{
m->internal = 1;
MenuShow(m, 1);
ewin = m->ewin;
if (ewin)
{
EwinMove(ewin, lx, ly);
ShowEwin(ewin);
}
}
done:
if (lst)
Efree(lst);
return m;
}
@ -1046,7 +1028,7 @@ MenusShowNamed(const char *name)
if (MenusActive())
MenusHide();
m = FindItem(name, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU);
m = MenuFind(name);
if (!m)
return;
@ -1054,35 +1036,6 @@ MenusShowNamed(const char *name)
MenuShow(m, 0);
}
void
ShowInternalMenu(Menu ** pm, MenuStyle ** pms, const char *style,
Menu * (mcf) (const char *name, MenuStyle * ms))
{
Menu *m = *pm;
MenuStyle *ms = *pms;
/* Hide any menus currently up */
if (MenusActive())
MenusHide();
if (!ms)
{
ms = FindItem(style, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (!ms)
ms = FindItem("DEFAULT", 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (!ms)
return;
*pms = ms;
}
*pm = m = RefreshInternalMenu(m, ms, mcf);
if (!m)
return;
if (!m->ewin)
MenuShow(m, 0);
}
int
MenusActive(void)
{
@ -1210,9 +1163,9 @@ MenuEventKeyPress(Menu * m, XEvent * ev)
break;
if (!mi->params)
break;
EFuncDefer(Mode_menus.context_ewin, mi->params);
MenusHide();
EobjsRepaint();
EFunc(Mode_menus.context_ewin, mi->params);
break;
}
}
@ -1246,10 +1199,9 @@ MenuItemEventMouseUp(MenuItem * mi, XEvent * ev __UNUSED__)
MenuDrawItem(m, mi, 1, STATE_HILITED);
if ((mi->params) /* && (!Mode_menus.just_shown) */ )
{
EFuncDefer(Mode_menus.context_ewin, mi->params);
MenusHide();
EobjsRepaint();
EFunc(Mode_menus.context_ewin, mi->params);
return;
}
}
}
@ -1856,62 +1808,12 @@ MenuConfigLoad(FILE * fs)
act = 0;
break;
case CONFIG_CLOSE:
if (m)
MenuRealize(m);
err = 0;
break;
case MENU_PREBUILT:
sscanf(s, "%i %4000s %4000s %4000s %4000s", &i1, s2, s3, s4, s5);
if (!strcmp(s4, "dirscan"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (!ms)
ms = FindItem("DEFAULT", 0, LIST_FINDBY_NAME,
LIST_TYPE_MENU_STYLE);
if (ms)
{
SoundPlay("SOUND_SCANNING");
m = MenuCreateFromDirectory(s2, NULL, ms, s5);
}
}
else if (!strcmp(s4, "gnome"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromGnome(s2, NULL, ms, s5);
}
else if (!strcmp(s4, "borders"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromBorders(s2, ms);
}
else if (!strcmp(s4, "themes"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromThemes(s2, ms);
}
else if (!strcmp(s4, "file"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromFlatFile(s2, NULL, ms, s5);
}
else if (!strcmp(s4, "windowlist"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromAllEWins(s2, ms);
}
else if (!strcmp(s4, "desktopwindowlist"))
{
ms = FindItem(s3, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
m = MenuCreateFromDesktops(s2, ms);
}
m = MenusCreateInternal(s4, s2, s3, s5);
break;
case CONFIG_CLASSNAME:
if (!m)
@ -1920,11 +1822,9 @@ MenuConfigLoad(FILE * fs)
MenuSetName(m, s2);
break;
case MENU_USE_STYLE:
{
ms = FindItem(s2, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
MenuSetStyle(m, ms);
}
ms = FindItem(s2, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU_STYLE);
if (ms)
MenuSetStyle(m, ms);
break;
case MENU_TITLE:
if (m)
@ -1982,12 +1882,13 @@ MenuConfigLoad(FILE * fs)
if (strcmp("NULL", s3))
ic = ImageclassFind(s3, 0);
mm = FindItem(s2, 0, LIST_FINDBY_NAME, LIST_TYPE_MENU);
#if 0 /* FIXME - Remove? */
/* if submenu empty - dont put it in - only if menu found */
if (MenuIsNotEmpty(mm))
{
mi = MenuItemCreate(atword(s, 4), ic, NULL, mm);
MenuAddItem(m, mi);
}
if (MenuIsEmpty(mm))
break;
#endif
mi = MenuItemCreate(atword(s, 4), ic, NULL, mm);
MenuAddItem(m, mi);
break;
default:
break;
@ -2002,6 +1903,32 @@ MenuConfigLoad(FILE * fs)
return err;
}
static void
MenusTimeout(int val __UNUSED__, void *data __UNUSED__)
{
Menu *m, **lst;
int i, num;
time_t ts;
/* Unload contents if loadable and no access in > 5 min */
ts = time(0);
lst = (Menu **) ListItemType(&num, LIST_TYPE_MENU);
for (i = 0; i < num; i++)
{
m = lst[i];
if (!m->loader || m->shown || m->num == 0 ||
m->last_access == 0 || ts - m->last_access < 300)
continue;
MenuEmpty(m, 0);
m->last_change = 0;
m->last_access = 0;
}
if (lst)
Efree(lst);
DoIn("MenusCheck", 300.0, MenusTimeout, 0, NULL);
}
/*
* Menus Module
*/
@ -2015,6 +1942,10 @@ MenusSighan(int sig, void *prm __UNUSED__)
ConfigFileLoad("menus.cfg", NULL, MenuConfigLoad, 1);
break;
case ESIGNAL_START:
DoIn("MenusCheck", 300.0, MenusTimeout, 0, NULL);
break;
case ESIGNAL_AREA_SWITCH_START:
case ESIGNAL_DESK_SWITCH_START:
MenusHide();
@ -2054,11 +1985,10 @@ MenusIpc(const char *params, Client * c __UNUSED__)
lst = (Menu **) ListItemType(&num, LIST_TYPE_MENU);
for (i = 0; i < num; i++)
{
IpcPrintf("%s\n", MenuGetName(lst[i]));
IpcPrintf("%s\n", lst[i]->name);
}
if (lst)
Efree(lst);
}
else if (!strncmp(cmd, "reload", 2))
{
@ -2067,36 +1997,10 @@ MenusIpc(const char *params, Client * c __UNUSED__)
}
else if (!strncmp(cmd, "show", 2))
{
/* FIXME - Menus should have update function? */
void ShowAllTaskMenu(void);
void ShowDeskMenu(void);
void ShowGroupMenu(void);
if (!strcmp(prm, "deskmenu"))
{
SoundPlay("SOUND_MENU_SHOW");
ShowDeskMenu();
}
else if (!strcmp(prm, "taskmenu"))
{
SoundPlay("SOUND_MENU_SHOW");
ShowAllTaskMenu();
}
else if (!strcmp(prm, "groupmenu"))
{
SoundPlay("SOUND_MENU_SHOW");
ShowGroupMenu();
}
else if (!strcmp(prm, "named"))
{
SoundPlay("SOUND_MENU_SHOW");
MenusShowNamed(p);
}
else
{
SoundPlay("SOUND_MENU_SHOW");
MenusShowNamed(prm);
}
if (strcmp(prm, "named"))
p = prm;
SoundPlay("SOUND_MENU_SHOW");
MenusShowNamed(p);
}
}

View File

@ -29,6 +29,8 @@ typedef struct _menu Menu;
typedef struct _menuitem MenuItem;
typedef struct _menustyle MenuStyle;
typedef int (MenuLoader) (Menu * m);
/* menus.c */
int MenuStyleConfigLoad(FILE * fs);
@ -36,39 +38,28 @@ Menu *MenuCreate(const char *name, const char *title,
Menu * parent, MenuStyle * ms);
void MenuDestroy(Menu * m);
void MenuHide(Menu * m);
void MenuEmpty(Menu * m);
void MenuEmpty(Menu * m, int destroying);
void MenuRepack(Menu * m);
MenuItem *MenuItemCreate(const char *text, ImageClass * ic,
const char *action_params, Menu * child);
void MenuSetInternal(Menu * m);
void MenuSetDynamic(Menu * m);
void MenuSetName(Menu * m, const char *name);
void MenuSetAlias(Menu * m, const char *alias);
void MenuSetStyle(Menu * m, MenuStyle * ms);
void MenuSetTitle(Menu * m, const char *title);
void MenuSetData(Menu * m, char *data);
void MenuSetLoader(Menu * m, MenuLoader * loader);
void MenuSetTimestamp(Menu * m, time_t t);
void MenuAddItem(Menu * m, MenuItem * mi);
const char *MenuGetName(const Menu * m);
const char *MenuGetData(const Menu * m);
time_t MenuGetTimestamp(const Menu * m);
int MenuIsNotEmpty(const Menu * m);
void MenuAddItem(Menu * m, MenuItem * mi);
void ShowInternalMenu(Menu ** pm, MenuStyle ** pms,
const char *style,
Menu * (mcf) (const char *name,
MenuStyle * ms));
int MenusActive(void);
/* menus-misc.c */
Menu *MenuCreateFromDirectory(const char *name, Menu * parent,
MenuStyle * ms, const char *dir);
Menu *MenuCreateFromFlatFile(const char *name, Menu * parent,
MenuStyle * ms, const char *file);
Menu *MenuCreateFromGnome(const char *name, Menu * parent,
MenuStyle * ms, const char *dir);
Menu *MenuCreateFromAllEWins(const char *name, MenuStyle * ms);
Menu *MenuCreateFromDesktopEWins(const char *name, MenuStyle * ms,
int desk);
Menu *MenuCreateFromDesktops(const char *name, MenuStyle * ms);
Menu *MenuCreateFromThemes(const char *name, MenuStyle * ms);
Menu *MenuCreateFromBorders(const char *name, MenuStyle * ms);
Menu *MenusCreateInternal(const char *type, const char *name,
const char *style, const char *prm);
#endif /* _MENUS_H_ */

View File

@ -476,7 +476,7 @@ ThemesIpc(const char *params, Client * c __UNUSED__)
IpcItem ThemeIpcArray[] = {
{
ThemesIpc,
"themes", "th",
"theme", "th",
"Theme commands",
" theme Show current theme\n"
" theme list Show all themes\n"