1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-04 21:04:18 +01:00

Remove code duplication in winmenu.c

There are some code duplication in winmenu.c. Two new functions,

- open_window_menu_core
- prepare_menu_position

Join the common code and then the duplicated code can be removed.
This commit is contained in:
Rodolfo García Peñas (kix)
2012-06-23 13:05:30 +02:00
committed by Carlos R. Mafra
parent b6ced4fa5d
commit a5eb4910e4

View File

@@ -576,11 +576,10 @@ static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
wMenuRealize(menu); wMenuRealize(menu);
} }
void OpenWindowMenu(WWindow * wwin, int x, int y, int keyboard) static WMenu *open_window_menu_core(WWindow *wwin, int x, int y)
{ {
WMenu *menu;
WScreen *scr = wwin->screen_ptr; WScreen *scr = wwin->screen_ptr;
WMRect rect; WMenu *menu;
wwin->flags.menu_open_for_me = 1; wwin->flags.menu_open_for_me = 1;
@@ -598,18 +597,18 @@ void OpenWindowMenu(WWindow * wwin, int x, int y, int keyboard)
menu = scr->window_menu; menu = scr->window_menu;
if (menu->flags.mapped) { if (menu->flags.mapped) {
wMenuUnmap(menu); wMenuUnmap(menu);
if (menu->entries[0]->clientdata == wwin) { if (menu->entries[0]->clientdata == wwin)
return; return NULL;
}
} }
updateMenuForWindow(menu, wwin); updateMenuForWindow(menu, wwin);
x -= menu->frame->core->width / 2; return menu;
if (x + menu->frame->core->width > wwin->frame_x + wwin->frame->core->width) }
x = wwin->frame_x + wwin->frame->core->width - menu->frame->core->width;
if (x < wwin->frame_x) static void prepare_menu_position(WMenu *menu, int x, int y)
x = wwin->frame_x; {
WMRect rect;
rect = wGetRectForHead(menu->frame->screen_ptr, rect = wGetRectForHead(menu->frame->screen_ptr,
wGetHeadForPointerLocation(menu->frame->screen_ptr)); wGetHeadForPointerLocation(menu->frame->screen_ptr));
@@ -617,6 +616,25 @@ void OpenWindowMenu(WWindow * wwin, int x, int y, int keyboard)
x = rect.pos.x - menu->frame->core->width / 2; x = rect.pos.x - menu->frame->core->width / 2;
if (y < rect.pos.y) if (y < rect.pos.y)
y = rect.pos.y; y = rect.pos.y;
}
void OpenWindowMenu(WWindow *wwin, int x, int y, int keyboard)
{
WMenu *menu;
menu = open_window_menu_core(wwin, x, y);
if (!menu)
return;
/* Specific menu position */
x -= menu->frame->core->width / 2;
if (x + menu->frame->core->width > wwin->frame_x + wwin->frame->core->width)
x = wwin->frame_x + wwin->frame->core->width - menu->frame->core->width;
if (x < wwin->frame_x)
x = wwin->frame_x;
/* Common menu position */
prepare_menu_position(menu, x, y);
if (!wwin->flags.internal_window) if (!wwin->flags.internal_window)
wMenuMapAt(menu, x, y, keyboard); wMenuMapAt(menu, x, y, keyboard);
@@ -627,31 +645,12 @@ void OpenWindowMenu2(WWindow *wwin, int x, int y, int keyboard)
int i; int i;
WMenu *menu; WMenu *menu;
WScreen *scr = wwin->screen_ptr; WScreen *scr = wwin->screen_ptr;
WMRect rect;
wwin->flags.menu_open_for_me = 1; menu = open_window_menu_core(wwin, x, y);
if (!menu)
if (!scr->window_menu) { return;
scr->window_menu = createWindowMenu(scr);
/* hack to save some memory allocation/deallocation */
wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
wfree(scr->window_menu->entries[MC_SHADE]->text);
} else {
updateWorkspaceMenu(scr->workspace_submenu);
}
menu = scr->window_menu;
if (menu->flags.mapped) {
wMenuUnmap(menu);
if (menu->entries[0]->clientdata == wwin) {
return;
}
}
updateMenuForWindow(menu, wwin);
/* Specific menu position */
for (i = 0; i < scr->workspace_submenu->entry_no; i++) { for (i = 0; i < scr->workspace_submenu->entry_no; i++) {
scr->workspace_submenu->entries[i]->clientdata = wwin; scr->workspace_submenu->entries[i]->clientdata = wwin;
wMenuSetEnabled(scr->workspace_submenu, i, True); wMenuSetEnabled(scr->workspace_submenu, i, True);
@@ -659,12 +658,8 @@ void OpenWindowMenu2(WWindow *wwin, int x, int y, int keyboard)
x -= menu->frame->core->width / 2; x -= menu->frame->core->width / 2;
rect = wGetRectForHead(menu->frame->screen_ptr, /* Common menu position */
wGetHeadForPointerLocation(menu->frame->screen_ptr)); prepare_menu_position(menu, x, y);
if (x < rect.pos.x - menu->frame->core->width / 2)
x = rect.pos.x - menu->frame->core->width / 2;
if (y < rect.pos.y)
y = rect.pos.y;
if (!wwin->flags.internal_window) if (!wwin->flags.internal_window)
wMenuMapAt(menu, x, y, keyboard); wMenuMapAt(menu, x, y, keyboard);
@@ -673,30 +668,10 @@ void OpenWindowMenu2(WWindow *wwin, int x, int y, int keyboard)
void OpenMiniwindowMenu(WWindow * wwin, int x, int y) void OpenMiniwindowMenu(WWindow * wwin, int x, int y)
{ {
WMenu *menu; WMenu *menu;
WScreen *scr = wwin->screen_ptr;
wwin->flags.menu_open_for_me = 1; menu = open_window_menu_core(wwin, x, y);
if (!menu)
if (!scr->window_menu) { return;
scr->window_menu = createWindowMenu(scr);
/* hack to save some memory allocation/deallocation */
wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
wfree(scr->window_menu->entries[MC_SHADE]->text);
} else {
updateWorkspaceMenu(scr->workspace_submenu);
}
menu = scr->window_menu;
if (menu->flags.mapped) {
wMenuUnmap(menu);
if (menu->entries[0]->clientdata == wwin) {
return;
}
}
updateMenuForWindow(menu, wwin);
x -= menu->frame->core->width / 2; x -= menu->frame->core->width / 2;