mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-13 20:35:54 +01:00
- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the
first element in the array that is matched by match(item, cdata)==True. - added WMArrayFirst(), WMArrayLast(), WMArrayNext() and WMArrayPrevious() functions and also WM_ITERATE_ARRAY() and WM_ETARETI_ARRAY() macros, to make interfaces to WMBag and WMArray similar and to make life a little simpler when iterating through all elements of an array. - replaced bags with arrays wherever appropriate. This will improve performance a bit. - replaced some recursive code with iterative code in WINGs/selection.c - some code cleanup is src/
This commit is contained in:
@@ -1699,8 +1699,8 @@ wSelectWindow(WWindow *wwin, Bool flag)
|
||||
}
|
||||
|
||||
if (!scr->selected_windows)
|
||||
scr->selected_windows = WMCreateBag(4);
|
||||
WMPutInBag(scr->selected_windows, wwin);
|
||||
scr->selected_windows = WMCreateArray(4);
|
||||
WMAddToArray(scr->selected_windows, wwin);
|
||||
} else {
|
||||
wwin->flags.selected = 0;
|
||||
XSetWindowBorder(dpy, wwin->frame->core->window,
|
||||
@@ -1711,7 +1711,7 @@ wSelectWindow(WWindow *wwin, Bool flag)
|
||||
}
|
||||
|
||||
if (scr->selected_windows) {
|
||||
WMRemoveFromBag(scr->selected_windows, wwin);
|
||||
WMRemoveFromArray(scr->selected_windows, wwin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
src/dock.c
72
src/dock.c
@@ -292,17 +292,17 @@ numberOfSelectedIcons(WDock *dock)
|
||||
}
|
||||
|
||||
|
||||
static WMBag*
|
||||
static WMArray*
|
||||
getSelected(WDock *dock)
|
||||
{
|
||||
WMBag *ret = WMCreateBag(8);
|
||||
WMArray *ret = WMCreateArray(8);
|
||||
WAppIcon *btn;
|
||||
int i;
|
||||
|
||||
for (i=1; i<dock->max_icons; i++) {
|
||||
btn = dock->icon_array[i];
|
||||
if (btn && btn->icon->selected) {
|
||||
WMPutInBag(ret, btn);
|
||||
WMAddToArray(ret, btn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,9 +461,9 @@ omnipresentCallback(WMenu *menu, WMenuEntry *entry)
|
||||
WAppIcon *clickedIcon = entry->clientdata;
|
||||
WAppIcon *aicon;
|
||||
WDock *dock;
|
||||
WMBag *selectedIcons;
|
||||
WMArray *selectedIcons;
|
||||
WMArrayIterator iter;
|
||||
int failed;
|
||||
int i;
|
||||
|
||||
assert(entry->clientdata!=NULL);
|
||||
|
||||
@@ -471,19 +471,17 @@ omnipresentCallback(WMenu *menu, WMenuEntry *entry)
|
||||
|
||||
selectedIcons = getSelected(dock);
|
||||
|
||||
if (!WMGetBagItemCount(selectedIcons))
|
||||
WMPutInBag(selectedIcons, clickedIcon);
|
||||
if (!WMGetArrayItemCount(selectedIcons))
|
||||
WMAddToArray(selectedIcons, clickedIcon);
|
||||
|
||||
failed = 0;
|
||||
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) {
|
||||
aicon = WMGetFromBag(selectedIcons, i);
|
||||
|
||||
WM_ITERATE_ARRAY(selectedIcons, aicon, iter) {
|
||||
if (wClipMakeIconOmnipresent(aicon, !aicon->omnipresent) == WO_FAILED)
|
||||
failed++;
|
||||
else if (aicon->icon->selected)
|
||||
wIconSelect(aicon->icon);
|
||||
}
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
|
||||
if (failed > 1) {
|
||||
wMessageDialog(dock->screen_ptr, _("Warning"),
|
||||
@@ -511,9 +509,9 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
|
||||
WDock *dock;
|
||||
WAppIcon *aicon;
|
||||
WMBag *selectedIcons;
|
||||
WMArray *selectedIcons;
|
||||
int keepit;
|
||||
WMBagIterator it;
|
||||
WMArrayIterator it;
|
||||
|
||||
assert(clickedIcon!=NULL);
|
||||
|
||||
@@ -521,22 +519,22 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
|
||||
selectedIcons = getSelected(dock);
|
||||
|
||||
if (WMGetBagItemCount(selectedIcons)) {
|
||||
if (WMGetArrayItemCount(selectedIcons)) {
|
||||
if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"),
|
||||
_("All selected icons will be removed!"),
|
||||
_("OK"), _("Cancel"), NULL)!=WAPRDefault) {
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (clickedIcon->xindex==0 && clickedIcon->yindex==0) {
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
return;
|
||||
}
|
||||
WMPutInBag(selectedIcons, clickedIcon);
|
||||
WMAddToArray(selectedIcons, clickedIcon);
|
||||
}
|
||||
|
||||
WM_ITERATE_BAG(selectedIcons, aicon, it) {
|
||||
WM_ITERATE_ARRAY(selectedIcons, aicon, it) {
|
||||
keepit = aicon->running && wApplicationOf(aicon->main_window);
|
||||
wDockDetach(dock, aicon);
|
||||
if (keepit) {
|
||||
@@ -547,7 +545,7 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
XMapWindow(dpy, aicon->icon->core->window);
|
||||
}
|
||||
}
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
|
||||
if (wPreferences.auto_arrange_icons)
|
||||
wArrangeIcons(dock->screen_ptr, True);
|
||||
@@ -560,15 +558,15 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
|
||||
WDock *dock;
|
||||
WAppIcon *aicon;
|
||||
WMBag *selectedIcons;
|
||||
WMBagIterator it;
|
||||
WMArray *selectedIcons;
|
||||
WMArrayIterator it;
|
||||
|
||||
assert(clickedIcon!=NULL);
|
||||
dock = clickedIcon->dock;
|
||||
|
||||
selectedIcons = getSelected(dock);
|
||||
|
||||
if (!WMGetBagItemCount(selectedIcons)
|
||||
if (!WMGetArrayItemCount(selectedIcons)
|
||||
&& clickedIcon!=dock->screen_ptr->clip_icon) {
|
||||
char *command = NULL;
|
||||
|
||||
@@ -588,15 +586,15 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
clickedIcon->editing = 0;
|
||||
if (command)
|
||||
wfree(command);
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
WMPutInBag(selectedIcons, clickedIcon);
|
||||
WMAddToArray(selectedIcons, clickedIcon);
|
||||
}
|
||||
|
||||
WM_ITERATE_BAG(selectedIcons, aicon, it) {
|
||||
WM_ITERATE_ARRAY(selectedIcons, aicon, it) {
|
||||
if (aicon->icon->selected)
|
||||
wIconSelect(aicon->icon);
|
||||
if (aicon && aicon->attracted && aicon->command) {
|
||||
@@ -608,7 +606,7 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
}
|
||||
|
||||
|
||||
@@ -695,7 +693,8 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
{
|
||||
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
|
||||
WDock *dock;
|
||||
WMBag *selectedIcons;
|
||||
WMArray *selectedIcons;
|
||||
WMArrayIterator iter;
|
||||
WAppIcon *btn;
|
||||
int i;
|
||||
|
||||
@@ -704,7 +703,7 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
|
||||
selectedIcons = getSelected(dock);
|
||||
|
||||
if (!WMGetBagItemCount(selectedIcons)) {
|
||||
if (!WMGetArrayItemCount(selectedIcons)) {
|
||||
for (i=1; i<dock->max_icons; i++) {
|
||||
btn = dock->icon_array[i];
|
||||
if (btn && !btn->icon->selected) {
|
||||
@@ -712,12 +711,11 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) {
|
||||
btn = WMGetFromBag(selectedIcons, i);
|
||||
WM_ITERATE_ARRAY(selectedIcons, btn, iter) {
|
||||
wIconSelect(btn->icon);
|
||||
}
|
||||
}
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
|
||||
wMenuPaint(menu);
|
||||
}
|
||||
@@ -861,7 +859,7 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
|
||||
WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata;
|
||||
WScreen *scr = icon->icon->core->screen_ptr;
|
||||
WDock *src, *dest;
|
||||
WMBag *selectedIcons;
|
||||
WMArray *selectedIcons;
|
||||
int x, y;
|
||||
|
||||
if (entry->order == scr->current_workspace)
|
||||
@@ -871,10 +869,10 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
|
||||
|
||||
selectedIcons = getSelected(src);
|
||||
|
||||
if (WMGetBagItemCount(selectedIcons)) {
|
||||
int i;
|
||||
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) {
|
||||
btn = WMGetFromBag(selectedIcons, i);
|
||||
if (WMGetArrayItemCount(selectedIcons)) {
|
||||
WMArrayIterator iter;
|
||||
|
||||
WM_ITERATE_ARRAY(selectedIcons, btn, iter) {
|
||||
if (wDockFindFreeSlot(dest, &x, &y)) {
|
||||
moveIconBetweenDocks(src, dest, btn, x, y);
|
||||
XUnmapWindow(dpy, btn->icon->core->window);
|
||||
@@ -886,7 +884,7 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
|
||||
XUnmapWindow(dpy, icon->icon->core->window);
|
||||
}
|
||||
}
|
||||
WMFreeBag(selectedIcons);
|
||||
WMFreeArray(selectedIcons);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ ShowDockAppSettingsPanel(WAppIcon *aicon)
|
||||
WMResizeWidget(panel->autoLaunchBtn, PWIDTH-30, 20);
|
||||
WMMoveWidget(panel->autoLaunchBtn, 15, 80);
|
||||
WMSetButtonText(panel->autoLaunchBtn,
|
||||
_("Start when WindowMaker is started"));
|
||||
_("Start when Window Maker is started"));
|
||||
WMSetButtonSelected(panel->autoLaunchBtn, aicon->auto_launch);
|
||||
|
||||
panel->lockBtn = WMCreateSwitchButton(panel->win);
|
||||
|
||||
74
src/event.c
74
src/event.c
@@ -156,7 +156,7 @@ typedef struct DeathHandler {
|
||||
void *client_data;
|
||||
} DeathHandler;
|
||||
|
||||
static WMBag *deathHandlers=NULL;
|
||||
static WMArray *deathHandlers=NULL;
|
||||
|
||||
|
||||
|
||||
@@ -174,9 +174,9 @@ wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
|
||||
handler->client_data = cdata;
|
||||
|
||||
if (!deathHandlers)
|
||||
deathHandlers = WMCreateBag(8);
|
||||
deathHandlers = WMCreateArrayWithDestructor(8, wfree);
|
||||
|
||||
WMPutInBag(deathHandlers, handler);
|
||||
WMAddToArray(deathHandlers, handler);
|
||||
|
||||
return handler;
|
||||
}
|
||||
@@ -191,9 +191,8 @@ wDeleteDeathHandler(WMagicNumber id)
|
||||
if (!handler || !deathHandlers)
|
||||
return;
|
||||
|
||||
WMRemoveFromBag(deathHandlers, handler);
|
||||
|
||||
wfree(handler);
|
||||
/* array destructor will call wfree(handler) */
|
||||
WMRemoveFromArray(deathHandlers, handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,8 +383,8 @@ handleDeadProcess(void *foo)
|
||||
while (deadProcessPtr>0) {
|
||||
deadProcessPtr--;
|
||||
|
||||
for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
|
||||
tmp = WMGetFromBag(deathHandlers, i);
|
||||
for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
|
||||
tmp = WMGetFromArray(deathHandlers, i);
|
||||
if (!tmp)
|
||||
continue;
|
||||
|
||||
@@ -1514,25 +1513,20 @@ handleKeyPress(XEvent *event)
|
||||
case WKBD_WINDOW9:
|
||||
case WKBD_WINDOW10:
|
||||
|
||||
#define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
|
||||
|
||||
index = command-WKBD_WINDOW1;
|
||||
|
||||
if (scr->shortcutWindows[index]) {
|
||||
WMBag *list = scr->shortcutWindows[index];
|
||||
WMArray *list = scr->shortcutWindows[index];
|
||||
int cw;
|
||||
int count = WMGetBagItemCount(list);
|
||||
int count = WMGetArrayItemCount(list);
|
||||
WWindow *twin;
|
||||
WMBagIterator iter;
|
||||
WMArrayIterator iter;
|
||||
WWindow *wwin;
|
||||
|
||||
wUnselectWindows(scr);
|
||||
cw = scr->current_workspace;
|
||||
|
||||
for (wwin = WMBagLast(list, &iter);
|
||||
iter != NULL;
|
||||
wwin = WMBagPrevious(list, &iter)) {
|
||||
|
||||
WM_ETARETI_ARRAY(list, wwin, iter) {
|
||||
if (count > 1)
|
||||
wWindowChangeWorkspace(wwin, cw);
|
||||
|
||||
@@ -1543,26 +1537,26 @@ handleKeyPress(XEvent *event)
|
||||
}
|
||||
|
||||
/* rotate the order of windows, to create a cycling effect */
|
||||
twin = WMBagFirst(list, &iter);
|
||||
WMRemoveFromBag(list, twin);
|
||||
WMPutInBag(list, twin);
|
||||
twin = WMGetFromArray(list, 0);
|
||||
WMDeleteFromArray(list, 0);
|
||||
WMAddToArray(list, twin);
|
||||
|
||||
} else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
|
||||
|
||||
INITBAG(scr->shortcutWindows[index]);
|
||||
WMPutInBag(scr->shortcutWindows[index], wwin);
|
||||
if (scr->shortcutWindows[index]) {
|
||||
WMFreeArray(scr->shortcutWindows[index]);
|
||||
scr->shortcutWindows[index] = NULL;
|
||||
}
|
||||
|
||||
if (wwin->flags.selected && scr->selected_windows) {
|
||||
WMBag *selwins = scr->selected_windows;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < WMGetBagItemCount(selwins); i++) {
|
||||
WWindow *tmp = WMGetFromBag(selwins, i);
|
||||
|
||||
if (tmp != wwin)
|
||||
WMPutInBag(scr->shortcutWindows[index], tmp);
|
||||
}
|
||||
scr->shortcutWindows[index] =
|
||||
WMDuplicateArray(scr->selected_windows);
|
||||
/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
|
||||
WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
|
||||
} else {
|
||||
scr->shortcutWindows[index] = WMCreateArray(4);
|
||||
WMAddToArray(scr->shortcutWindows[index], wwin);
|
||||
}
|
||||
|
||||
wSelectWindow(wwin, !wwin->flags.selected);
|
||||
XFlush(dpy);
|
||||
wusleep(3000);
|
||||
@@ -1570,22 +1564,16 @@ handleKeyPress(XEvent *event)
|
||||
XFlush(dpy);
|
||||
|
||||
} else if (scr->selected_windows
|
||||
&& WMGetBagItemCount(scr->selected_windows)) {
|
||||
&& WMGetArrayItemCount(scr->selected_windows)) {
|
||||
|
||||
if (wwin->flags.selected && scr->selected_windows) {
|
||||
WMBag *selwins = scr->selected_windows;
|
||||
int i;
|
||||
|
||||
INITBAG(scr->shortcutWindows[index]);
|
||||
|
||||
for (i = 0; i < WMGetBagItemCount(selwins); i++) {
|
||||
WWindow *tmp = WMGetFromBag(selwins, i);
|
||||
|
||||
WMPutInBag(scr->shortcutWindows[index], tmp);
|
||||
if (scr->shortcutWindows[index]) {
|
||||
WMFreeArray(scr->shortcutWindows[index]);
|
||||
}
|
||||
scr->shortcutWindows[index] =
|
||||
WMDuplicateArray(scr->selected_windows);
|
||||
}
|
||||
}
|
||||
#undef INITBAG
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@@ -390,19 +390,19 @@ mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
|
||||
|
||||
|
||||
static void
|
||||
doWindowMove(WWindow *wwin, WMBag *bag, int dx, int dy)
|
||||
doWindowMove(WWindow *wwin, WMArray *array, int dx, int dy)
|
||||
{
|
||||
WWindow *tmpw;
|
||||
int x, y;
|
||||
int scr_width = wwin->screen_ptr->scr_width;
|
||||
int scr_height = wwin->screen_ptr->scr_height;
|
||||
|
||||
if (!bag || !WMGetBagItemCount(bag)) {
|
||||
if (!array || !WMGetArrayItemCount(array)) {
|
||||
wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; i < WMGetBagItemCount(bag); i++) {
|
||||
tmpw = WMGetFromBag(bag, i);
|
||||
WMArrayIterator iter;
|
||||
|
||||
WM_ITERATE_ARRAY(array, tmpw, iter) {
|
||||
x = tmpw->frame_x + dx;
|
||||
y = tmpw->frame_y + dy;
|
||||
|
||||
@@ -455,14 +455,14 @@ drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
|
||||
|
||||
|
||||
static void
|
||||
drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
|
||||
drawFrames(WWindow *wwin, WMArray *array, int dx, int dy)
|
||||
{
|
||||
WWindow *tmpw;
|
||||
int scr_width = wwin->screen_ptr->scr_width;
|
||||
int scr_height = wwin->screen_ptr->scr_height;
|
||||
int x, y;
|
||||
|
||||
if (!bag) {
|
||||
if (!array) {
|
||||
|
||||
x = wwin->frame_x + dx;
|
||||
y = wwin->frame_y + dy;
|
||||
@@ -472,9 +472,9 @@ drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
|
||||
wwin->frame->core->height);
|
||||
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; i < WMGetBagItemCount(bag); i++) {
|
||||
tmpw = WMGetFromBag(bag, i);
|
||||
WMArrayIterator iter;
|
||||
|
||||
WM_ITERATE_ARRAY(array, tmpw, iter) {
|
||||
x = tmpw->frame_x + dx;
|
||||
y = tmpw->frame_y + dy;
|
||||
|
||||
@@ -1492,11 +1492,13 @@ wKeyboardMoveResizeWindow(WWindow *wwin)
|
||||
wWindowMove(wwin, src_x+off_x, src_y+off_y);
|
||||
wWindowSynthConfigureNotify(wwin);
|
||||
} else {
|
||||
int i;
|
||||
WMBag *bag = scr->selected_windows;
|
||||
doWindowMove(wwin,scr->selected_windows,off_x,off_y);
|
||||
for (i = 0; i < WMGetBagItemCount(bag); i++) {
|
||||
wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
|
||||
WMArrayIterator iter;
|
||||
WWindow *foo;
|
||||
|
||||
doWindowMove(wwin, scr->selected_windows, off_x, off_y);
|
||||
|
||||
WM_ITERATE_ARRAY(scr->selected_windows, foo, iter) {
|
||||
wWindowSynthConfigureNotify(foo);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2096,16 +2098,14 @@ wUnselectWindows(WScreen *scr)
|
||||
if (!scr->selected_windows)
|
||||
return;
|
||||
|
||||
while (WMGetBagItemCount(scr->selected_windows)) {
|
||||
WMBagIterator dummy;
|
||||
|
||||
wwin = WMBagFirst(scr->selected_windows, &dummy);
|
||||
while (WMGetArrayItemCount(scr->selected_windows)) {
|
||||
wwin = WMGetFromArray(scr->selected_windows, 0);
|
||||
if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
|
||||
wIconSelect(wwin->icon);
|
||||
|
||||
wSelectWindow(wwin, False);
|
||||
}
|
||||
WMFreeBag(scr->selected_windows);
|
||||
WMFreeArray(scr->selected_windows);
|
||||
scr->selected_windows = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -601,7 +601,7 @@ static void
|
||||
separateCommand(char *line, char ***file, char **command)
|
||||
{
|
||||
char *token, *tmp = line;
|
||||
WMBag *bag = WMCreateBag(4);
|
||||
WMArray *array = WMCreateArray(4);
|
||||
int count, i;
|
||||
|
||||
*file = NULL;
|
||||
@@ -616,19 +616,19 @@ separateCommand(char *line, char ***file, char **command)
|
||||
wwarning(_("%s: missing command"), line);
|
||||
break;
|
||||
}
|
||||
WMPutInBag(bag, token);
|
||||
WMAddToArray(array, token);
|
||||
}
|
||||
} while (token!=NULL && tmp!=NULL);
|
||||
|
||||
count = WMGetBagItemCount(bag);
|
||||
count = WMGetArrayItemCount(array);
|
||||
if (count>0) {
|
||||
*file = wmalloc(sizeof(char*)*(count+1));
|
||||
(*file)[count] = NULL;
|
||||
for (i = 0; i < count; i++) {
|
||||
(*file)[i] = WMGetFromBag(bag, i);
|
||||
(*file)[i] = WMGetFromArray(array, i);
|
||||
}
|
||||
}
|
||||
WMFreeBag(bag);
|
||||
WMFreeArray(array);
|
||||
}
|
||||
|
||||
|
||||
@@ -1334,14 +1334,15 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
struct stat stat_buf;
|
||||
WMenu *menu=NULL;
|
||||
char *buffer;
|
||||
WMBag *dirs = NULL, *files = NULL;
|
||||
WMArray *dirs = NULL, *files = NULL;
|
||||
WMArrayIterator iter;
|
||||
int length, i, have_space=0;
|
||||
dir_data *data;
|
||||
int stripExtension = 0;
|
||||
|
||||
|
||||
dirs = WMCreateBag(16);
|
||||
files = WMCreateBag(16);
|
||||
dirs = WMCreateArray(16);
|
||||
files = WMCreateArray(16);
|
||||
|
||||
i=0;
|
||||
while (path[i]!=NULL) {
|
||||
@@ -1395,7 +1396,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
data->name = wstrdup(dentry->d_name);
|
||||
data->index = i;
|
||||
|
||||
WMPutInBag(dirs, data);
|
||||
WMAddToArray(dirs, data);
|
||||
}
|
||||
} else if (S_ISREG(stat_buf.st_mode) || isFilePack) {
|
||||
/* Hack because access always returns X_OK success for user root */
|
||||
@@ -1408,7 +1409,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
data->name = wstrdup(dentry->d_name);
|
||||
data->index = i;
|
||||
|
||||
WMPutInBag(files, data);
|
||||
WMAddToArray(files, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1419,24 +1420,22 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
i++;
|
||||
}
|
||||
|
||||
if (!WMGetBagItemCount(dirs) && !WMGetBagItemCount(files)) {
|
||||
WMFreeBag(dirs);
|
||||
WMFreeBag(files);
|
||||
if (!WMGetArrayItemCount(dirs) && !WMGetArrayItemCount(files)) {
|
||||
WMFreeArray(dirs);
|
||||
WMFreeArray(files);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WMSortBag(dirs, myCompare);
|
||||
WMSortBag(files, myCompare);
|
||||
WMSortArray(dirs, myCompare);
|
||||
WMSortArray(files, myCompare);
|
||||
|
||||
menu = wMenuCreate(scr, title, False);
|
||||
menu->on_destroy = removeShortcutsForMenu;
|
||||
|
||||
for (i = 0; i < WMGetBagItemCount(dirs); i++) {
|
||||
WM_ITERATE_ARRAY(dirs, data, iter) {
|
||||
/* New directory. Use same OPEN_MENU command that was used
|
||||
* for the current directory. */
|
||||
dir_data *d = (dir_data*)WMGetFromBag(dirs, i);
|
||||
|
||||
length = strlen(path[d->index])+strlen(d->name)+6;
|
||||
length = strlen(path[data->index])+strlen(data->name)+6;
|
||||
if (stripExtension)
|
||||
length += 7;
|
||||
if (command)
|
||||
@@ -1444,7 +1443,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
buffer = malloc(length);
|
||||
if (!buffer) {
|
||||
wsyserror(_("out of memory while constructing directory menu %s"),
|
||||
path[d->index]);
|
||||
path[data->index]);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1452,15 +1451,15 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
if (stripExtension)
|
||||
strcat(buffer, "-noext ");
|
||||
|
||||
have_space = strchr(path[d->index], ' ')!=NULL ||
|
||||
strchr(d->name, ' ')!=NULL;
|
||||
have_space = strchr(path[data->index], ' ')!=NULL ||
|
||||
strchr(data->name, ' ')!=NULL;
|
||||
|
||||
if (have_space)
|
||||
strcat(buffer, "\"");
|
||||
strcat(buffer, path[d->index]);
|
||||
strcat(buffer, path[data->index]);
|
||||
|
||||
strcat(buffer, "/");
|
||||
strcat(buffer, d->name);
|
||||
strcat(buffer, data->name);
|
||||
if (have_space)
|
||||
strcat(buffer, "\"");
|
||||
if (command) {
|
||||
@@ -1468,66 +1467,64 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
|
||||
strcat(buffer, command);
|
||||
}
|
||||
|
||||
addMenuEntry(menu, d->name, NULL, "OPEN_MENU", buffer, path[d->index]);
|
||||
addMenuEntry(menu, data->name, NULL, "OPEN_MENU", buffer, path[data->index]);
|
||||
|
||||
wfree(buffer);
|
||||
if (d->name)
|
||||
wfree(d->name);
|
||||
wfree(d);
|
||||
if (data->name)
|
||||
wfree(data->name);
|
||||
wfree(data);
|
||||
}
|
||||
|
||||
for (i = 0; i < WMGetBagItemCount(files); i++) {
|
||||
WM_ITERATE_ARRAY(files, data, iter) {
|
||||
/* executable: add as entry */
|
||||
dir_data *f = (dir_data*)WMGetFromBag(files, i);
|
||||
|
||||
length = strlen(path[f->index])+strlen(f->name)+6;
|
||||
length = strlen(path[data->index])+strlen(data->name)+6;
|
||||
if (command)
|
||||
length += strlen(command);
|
||||
|
||||
buffer = malloc(length);
|
||||
if (!buffer) {
|
||||
wsyserror(_("out of memory while constructing directory menu %s"),
|
||||
path[f->index]);
|
||||
path[data->index]);
|
||||
break;
|
||||
}
|
||||
|
||||
have_space = strchr(path[f->index], ' ')!=NULL ||
|
||||
strchr(f->name, ' ')!=NULL;
|
||||
have_space = strchr(path[data->index], ' ')!=NULL ||
|
||||
strchr(data->name, ' ')!=NULL;
|
||||
if (command!=NULL) {
|
||||
strcpy(buffer, command);
|
||||
strcat(buffer, " ");
|
||||
if (have_space)
|
||||
strcat(buffer, "\"");
|
||||
strcat(buffer, path[f->index]);
|
||||
strcat(buffer, path[data->index]);
|
||||
} else {
|
||||
if (have_space) {
|
||||
buffer[0] = '"';
|
||||
buffer[1] = 0;
|
||||
strcat(buffer, path[f->index]);
|
||||
strcat(buffer, path[data->index]);
|
||||
} else {
|
||||
strcpy(buffer, path[f->index]);
|
||||
strcpy(buffer, path[data->index]);
|
||||
}
|
||||
}
|
||||
strcat(buffer, "/");
|
||||
strcat(buffer, f->name);
|
||||
strcat(buffer, data->name);
|
||||
if (have_space)
|
||||
strcat(buffer, "\"");
|
||||
|
||||
if (stripExtension) {
|
||||
char *ptr = strrchr(f->name, '.');
|
||||
if (ptr && ptr!=f->name)
|
||||
char *ptr = strrchr(data->name, '.');
|
||||
if (ptr && ptr!=data->name)
|
||||
*ptr = 0;
|
||||
}
|
||||
addMenuEntry(menu, f->name, NULL, "SHEXEC", buffer, path[f->index]);
|
||||
addMenuEntry(menu, data->name, NULL, "SHEXEC", buffer, path[data->index]);
|
||||
|
||||
wfree(buffer);
|
||||
if (f->name)
|
||||
wfree(f->name);
|
||||
wfree(f);
|
||||
if (data->name)
|
||||
wfree(data->name);
|
||||
wfree(data);
|
||||
}
|
||||
|
||||
WMFreeBag(files);
|
||||
WMFreeBag(dirs);
|
||||
WMFreeArray(files);
|
||||
WMFreeArray(dirs);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
@@ -107,8 +107,8 @@ typedef struct _WScreen {
|
||||
* Use this list if you want to
|
||||
* traverse the entire window list
|
||||
*/
|
||||
|
||||
WMBag *selected_windows;
|
||||
|
||||
WMArray *selected_windows;
|
||||
|
||||
struct WAppIcon *app_icon_list; /* list of all app-icons on screen */
|
||||
|
||||
@@ -291,7 +291,7 @@ typedef struct _WScreen {
|
||||
scrolled down for titlebar access */
|
||||
|
||||
/* for window shortcuts */
|
||||
WMBag *shortcutWindows[MAX_WINDOW_SHORTCUTS];
|
||||
WMArray *shortcutWindows[MAX_WINDOW_SHORTCUTS];
|
||||
|
||||
#ifdef XDND
|
||||
char *xdestring;
|
||||
|
||||
@@ -256,7 +256,7 @@ makeWindowState(WWindow *wwin, WApplication *wapp)
|
||||
|
||||
for (mask = 0, i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
|
||||
if (scr->shortcutWindows[i] != NULL &&
|
||||
WMGetFirstInBag(scr->shortcutWindows[i], wwin) != WBNotFound) {
|
||||
WMGetFirstInArray(scr->shortcutWindows[i], wwin) != WANotFound) {
|
||||
mask |= 1<<i;
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ wSessionSaveState(WScreen *scr)
|
||||
WWindow *wwin = scr->focused_window;
|
||||
proplist_t win_info, wks;
|
||||
proplist_t list=NULL;
|
||||
WMBag *wapp_list=NULL;
|
||||
WMArray *wapp_list=NULL;
|
||||
|
||||
|
||||
make_keys();
|
||||
@@ -327,13 +327,13 @@ wSessionSaveState(WScreen *scr)
|
||||
|
||||
list = PLMakeArrayFromElements(NULL);
|
||||
|
||||
wapp_list = WMCreateBag(16);
|
||||
wapp_list = WMCreateArray(16);
|
||||
|
||||
while (wwin) {
|
||||
WApplication *wapp=wApplicationOf(wwin->main_window);
|
||||
|
||||
if (wwin->transient_for==None
|
||||
&& WMGetFirstInBag(wapp_list, wapp)==WBNotFound
|
||||
&& WMGetFirstInArray(wapp_list, wapp)==WANotFound
|
||||
&& !WFLAGP(wwin, dont_save_session)) {
|
||||
/* A entry for this application was not yet saved. Save one. */
|
||||
if ((win_info = makeWindowState(wwin, wapp))!=NULL) {
|
||||
@@ -344,7 +344,7 @@ wSessionSaveState(WScreen *scr)
|
||||
* application list, so no multiple entries for the same
|
||||
* application are saved.
|
||||
*/
|
||||
WMPutInBag(wapp_list, wapp);
|
||||
WMAddToArray(wapp_list, wapp);
|
||||
}
|
||||
}
|
||||
wwin = wwin->prev;
|
||||
@@ -357,7 +357,7 @@ wSessionSaveState(WScreen *scr)
|
||||
PLInsertDictionaryEntry(scr->session_state, sWorkspace, wks);
|
||||
PLRelease(wks);
|
||||
|
||||
WMFreeBag(wapp_list);
|
||||
WMFreeArray(wapp_list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
src/window.c
12
src/window.c
@@ -227,10 +227,10 @@ wWindowDestroy(WWindow *wwin)
|
||||
if (!wwin->screen_ptr->shortcutWindows[i])
|
||||
continue;
|
||||
|
||||
WMRemoveFromBag(wwin->screen_ptr->shortcutWindows[i], wwin);
|
||||
WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
|
||||
|
||||
if (!WMGetBagItemCount(wwin->screen_ptr->shortcutWindows[i])) {
|
||||
WMFreeBag(wwin->screen_ptr->shortcutWindows[i]);
|
||||
if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
|
||||
WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
|
||||
wwin->screen_ptr->shortcutWindows[i] = NULL;
|
||||
}
|
||||
}
|
||||
@@ -862,9 +862,9 @@ wManageWindow(WScreen *scr, Window window)
|
||||
for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
|
||||
if (mask & (1<<i)) {
|
||||
if (!scr->shortcutWindows[i])
|
||||
scr->shortcutWindows[i] = WMCreateBag(4);
|
||||
scr->shortcutWindows[i] = WMCreateArray(4);
|
||||
|
||||
WMPutInBag(scr->shortcutWindows[i], wwin);
|
||||
WMAddToArray(scr->shortcutWindows[i], wwin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2372,7 +2372,7 @@ wWindowSaveState(WWindow *wwin)
|
||||
|
||||
for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
|
||||
if (wwin->screen_ptr->shortcutWindows[i] &&
|
||||
WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin))
|
||||
WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
|
||||
data[9] |= 1<<i;
|
||||
}
|
||||
XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
|
||||
|
||||
@@ -203,25 +203,17 @@ makeShortcutCommand(WMenu *menu, WMenuEntry *entry)
|
||||
int index = entry->order-WO_ENTRIES;
|
||||
|
||||
if (scr->shortcutWindows[index]) {
|
||||
WMFreeBag(scr->shortcutWindows[index]);
|
||||
WMFreeArray(scr->shortcutWindows[index]);
|
||||
scr->shortcutWindows[index] = NULL;
|
||||
}
|
||||
|
||||
if (wwin->flags.selected && scr->selected_windows) {
|
||||
WMBag *selwin = scr->selected_windows;
|
||||
int i;
|
||||
|
||||
scr->shortcutWindows[index] = WMCreateBag(4);
|
||||
|
||||
for (i = 0; i < WMGetBagItemCount(selwin); i++) {
|
||||
WWindow *tmp = WMGetFromBag(selwin, i);
|
||||
|
||||
WMPutInBag(scr->shortcutWindows[index], tmp);
|
||||
}
|
||||
scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
|
||||
/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
|
||||
WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
|
||||
} else {
|
||||
scr->shortcutWindows[index] = WMCreateBag(4);
|
||||
|
||||
WMPutInBag(scr->shortcutWindows[index], wwin);
|
||||
scr->shortcutWindows[index] = WMCreateArray(4);
|
||||
WMAddToArray(scr->shortcutWindows[index], wwin);
|
||||
}
|
||||
|
||||
wSelectWindow(wwin, !wwin->flags.selected);
|
||||
@@ -281,7 +273,7 @@ updateMakeShortcutMenu(WMenu *menu, WWindow *wwin)
|
||||
char *tmp;
|
||||
int shortcutNo = i-WO_ENTRIES;
|
||||
WMenuEntry *entry = smenu->entries[i];
|
||||
WMBag *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo];
|
||||
WMArray *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo];
|
||||
|
||||
sprintf(buffer, "%s %i", _("Set Shortcut"), shortcutNo+1);
|
||||
|
||||
@@ -289,7 +281,7 @@ updateMakeShortcutMenu(WMenu *menu, WWindow *wwin)
|
||||
entry->flags.indicator_on = 0;
|
||||
} else {
|
||||
entry->flags.indicator_on = 1;
|
||||
if (WMCountInBag(shortSelWindows, wwin))
|
||||
if (WMCountInArray(shortSelWindows, wwin))
|
||||
entry->flags.indicator_type = MI_DIAMOND;
|
||||
else
|
||||
entry->flags.indicator_type = MI_CHECK;
|
||||
|
||||
18
src/xdnd.c
18
src/xdnd.c
@@ -102,7 +102,7 @@ wXDNDProcessSelection(XEvent *event)
|
||||
char * delme;
|
||||
XEvent xevent;
|
||||
Window selowner = XGetSelectionOwner(dpy,_XA_XdndSelection);
|
||||
WMBag *items;
|
||||
WMArray *items;
|
||||
|
||||
|
||||
XGetWindowProperty(dpy, event->xselection.requestor,
|
||||
@@ -125,11 +125,12 @@ wXDNDProcessSelection(XEvent *event)
|
||||
|
||||
/*process dropping*/
|
||||
if (scr->xdestring) {
|
||||
WMArrayIterator iter;
|
||||
int length, str_size;
|
||||
int total_size = 0;
|
||||
char *tmp;
|
||||
|
||||
items = WMCreateBag(1);
|
||||
items = WMCreateArray(4);
|
||||
retain = wstrdup(scr->xdestring);
|
||||
XFree(scr->xdestring); /* since xdestring was created by Xlib */
|
||||
|
||||
@@ -143,24 +144,23 @@ wXDNDProcessSelection(XEvent *event)
|
||||
if (retain[length] == '\n') {
|
||||
str_size = strlen(&retain[length + 1]);
|
||||
if(str_size) {
|
||||
WMPutInBag(items, wstrdup(&retain[length + 1]));
|
||||
WMAddToArray(items, wstrdup(&retain[length + 1]));
|
||||
total_size += str_size + 3; /* reserve for " \"\"" */
|
||||
if (length)
|
||||
WMAppendBag(items, WMCreateBag(1));
|
||||
/* this is nonsense -- if (length)
|
||||
WMAppendArray(items, WMCreateArray(1));*/
|
||||
}
|
||||
retain[length] = 0;
|
||||
}
|
||||
}
|
||||
/* final one */
|
||||
WMPutInBag(items, wstrdup(retain));
|
||||
WMAddToArray(items, wstrdup(retain));
|
||||
total_size += strlen(retain) + 3;
|
||||
wfree(retain);
|
||||
|
||||
/* now pack new string */
|
||||
scr->xdestring = wmalloc(total_size);
|
||||
scr->xdestring[0]=0; /* empty string */
|
||||
for(length = WMGetBagItemCount(items)-1; length >=0; length--) {
|
||||
tmp = WMGetFromBag(items, length);
|
||||
WM_ETARETI_ARRAY(items, tmp, iter) {
|
||||
if (!strncmp(tmp,"file:",5)) {
|
||||
/* add more 2 chars while removing 5 is harmless */
|
||||
strcat(scr->xdestring, " \"");
|
||||
@@ -172,7 +172,7 @@ wXDNDProcessSelection(XEvent *event)
|
||||
}
|
||||
wfree(tmp);
|
||||
}
|
||||
WMFreeBag(items);
|
||||
WMFreeArray(items);
|
||||
wDockReceiveDNDDrop(scr,event);
|
||||
/*
|
||||
printf("free ");
|
||||
|
||||
Reference in New Issue
Block a user