mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 04:44:16 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
74
wmlib/app.c
74
wmlib/app.c
@@ -26,62 +26,54 @@
|
||||
#include "WMaker.h"
|
||||
#include "app.h"
|
||||
|
||||
|
||||
|
||||
WMAppContext*
|
||||
WMAppCreateWithMain(Display *display, int screen_number, Window main_window)
|
||||
WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window main_window)
|
||||
{
|
||||
wmAppContext *ctx;
|
||||
wmAppContext *ctx;
|
||||
|
||||
ctx = malloc(sizeof(wmAppContext));
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
ctx = malloc(sizeof(wmAppContext));
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
||||
ctx->dpy = display;
|
||||
ctx->screen_number = screen_number;
|
||||
ctx->our_leader_hint = False;
|
||||
ctx->main_window = main_window;
|
||||
ctx->windows = malloc(sizeof(Window));
|
||||
if (!ctx->windows) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
ctx->win_count = 1;
|
||||
ctx->windows[0] = main_window;
|
||||
ctx->dpy = display;
|
||||
ctx->screen_number = screen_number;
|
||||
ctx->our_leader_hint = False;
|
||||
ctx->main_window = main_window;
|
||||
ctx->windows = malloc(sizeof(Window));
|
||||
if (!ctx->windows) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
ctx->win_count = 1;
|
||||
ctx->windows[0] = main_window;
|
||||
|
||||
ctx->main_menu = NULL;
|
||||
ctx->main_menu = NULL;
|
||||
|
||||
ctx->last_menu_tag = 100;
|
||||
ctx->last_menu_tag = 100;
|
||||
|
||||
return ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
WMAppAddWindow(WMAppContext *app, Window window)
|
||||
int WMAppAddWindow(WMAppContext * app, Window window)
|
||||
{
|
||||
Window *win;
|
||||
Window *win;
|
||||
|
||||
win = malloc(sizeof(Window)*(app->win_count+1));
|
||||
if (!win)
|
||||
return False;
|
||||
win = malloc(sizeof(Window) * (app->win_count + 1));
|
||||
if (!win)
|
||||
return False;
|
||||
|
||||
memcpy(win, app->windows, sizeof(Window)*app->win_count);
|
||||
memcpy(win, app->windows, sizeof(Window) * app->win_count);
|
||||
|
||||
free(app->windows);
|
||||
free(app->windows);
|
||||
|
||||
win[app->win_count] = window;
|
||||
app->windows = win;
|
||||
app->win_count++;
|
||||
win[app->win_count] = window;
|
||||
app->windows = win;
|
||||
app->win_count++;
|
||||
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
WMAppSetMainMenu(WMAppContext *app, WMMenu *menu)
|
||||
int WMAppSetMainMenu(WMAppContext * app, WMMenu * menu)
|
||||
{
|
||||
app->main_menu = menu;
|
||||
return True;
|
||||
app->main_menu = menu;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,61 +25,50 @@
|
||||
#include "WMaker.h"
|
||||
#include "app.h"
|
||||
|
||||
static Atom
|
||||
getwmfunc(Display *dpy)
|
||||
static Atom getwmfunc(Display * dpy)
|
||||
{
|
||||
return XInternAtom(dpy, "_WINDOWMAKER_WM_FUNCTION", False);
|
||||
return XInternAtom(dpy, "_WINDOWMAKER_WM_FUNCTION", False);
|
||||
}
|
||||
|
||||
void
|
||||
WMHideApplication(WMAppContext *app)
|
||||
void WMHideApplication(WMAppContext * app)
|
||||
{
|
||||
XEvent event;
|
||||
XEvent event;
|
||||
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.message_type = getwmfunc(app->dpy);
|
||||
event.xclient.format = 32;
|
||||
event.xclient.display = app->dpy;
|
||||
event.xclient.window = app->main_window;
|
||||
event.xclient.data.l[0] = WMFHideApplication;
|
||||
event.xclient.data.l[1] = 0;
|
||||
event.xclient.data.l[2] = 0;
|
||||
event.xclient.data.l[3] = 0;
|
||||
XSendEvent(app->dpy, RootWindow(app->dpy, app->screen_number), False,
|
||||
SubstructureNotifyMask|SubstructureRedirectMask, &event);
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.message_type = getwmfunc(app->dpy);
|
||||
event.xclient.format = 32;
|
||||
event.xclient.display = app->dpy;
|
||||
event.xclient.window = app->main_window;
|
||||
event.xclient.data.l[0] = WMFHideApplication;
|
||||
event.xclient.data.l[1] = 0;
|
||||
event.xclient.data.l[2] = 0;
|
||||
event.xclient.data.l[3] = 0;
|
||||
XSendEvent(app->dpy, RootWindow(app->dpy, app->screen_number), False,
|
||||
SubstructureNotifyMask | SubstructureRedirectMask, &event);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMHideOthers(WMAppContext *app)
|
||||
void WMHideOthers(WMAppContext * app)
|
||||
{
|
||||
XEvent event;
|
||||
XEvent event;
|
||||
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.message_type = getwmfunc(app->dpy);
|
||||
event.xclient.format = 32;
|
||||
event.xclient.display = app->dpy;
|
||||
event.xclient.window = app->main_window;
|
||||
event.xclient.data.l[0] = WMFHideOtherApplications;
|
||||
event.xclient.data.l[1] = 0;
|
||||
event.xclient.data.l[2] = 0;
|
||||
event.xclient.data.l[3] = 0;
|
||||
XSendEvent(app->dpy, RootWindow(app->dpy, app->screen_number), False,
|
||||
SubstructureNotifyMask|SubstructureRedirectMask, &event);
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.message_type = getwmfunc(app->dpy);
|
||||
event.xclient.format = 32;
|
||||
event.xclient.display = app->dpy;
|
||||
event.xclient.window = app->main_window;
|
||||
event.xclient.data.l[0] = WMFHideOtherApplications;
|
||||
event.xclient.data.l[1] = 0;
|
||||
event.xclient.data.l[2] = 0;
|
||||
event.xclient.data.l[3] = 0;
|
||||
XSendEvent(app->dpy, RootWindow(app->dpy, app->screen_number), False,
|
||||
SubstructureNotifyMask | SubstructureRedirectMask, &event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
WMSetWindowAttributes(Display *dpy, Window window,
|
||||
GNUstepWMAttributes *attributes)
|
||||
void WMSetWindowAttributes(Display * dpy, Window window, GNUstepWMAttributes * attributes)
|
||||
{
|
||||
Atom atom;
|
||||
Atom atom;
|
||||
|
||||
atom = XInternAtom(dpy, "_GNUSTEP_WM_ATTR", False);
|
||||
XChangeProperty(dpy, window, atom, atom, 32, PropModeReplace,
|
||||
(unsigned char *)attributes,
|
||||
sizeof(GNUstepWMAttributes)/sizeof(CARD32));
|
||||
atom = XInternAtom(dpy, "_GNUSTEP_WM_ATTR", False);
|
||||
XChangeProperty(dpy, window, atom, atom, 32, PropModeReplace,
|
||||
(unsigned char *)attributes, sizeof(GNUstepWMAttributes) / sizeof(CARD32));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,69 +28,59 @@
|
||||
#include "app.h"
|
||||
#include "menu.h"
|
||||
|
||||
|
||||
static Atom _XA_WINDOWMAKER_MENU=0;
|
||||
static Atom _XA_WINDOWMAKER_MENU = 0;
|
||||
|
||||
enum {
|
||||
wmSelectItem = 1
|
||||
wmSelectItem = 1
|
||||
};
|
||||
|
||||
|
||||
static wmMenuEntry*
|
||||
findEntry(WMMenu *menu, int tag)
|
||||
static wmMenuEntry *findEntry(WMMenu * menu, int tag)
|
||||
{
|
||||
wmMenuEntry *entry=menu->first;
|
||||
wmMenuEntry *entry = menu->first;
|
||||
|
||||
while (entry) {
|
||||
if (entry->tag == tag) {
|
||||
return entry;
|
||||
}
|
||||
if (entry->cascade) {
|
||||
wmMenuEntry *tmp;
|
||||
tmp = findEntry(entry->cascade, tag);
|
||||
if (tmp)
|
||||
return tmp;
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
return NULL;
|
||||
while (entry) {
|
||||
if (entry->tag == tag) {
|
||||
return entry;
|
||||
}
|
||||
if (entry->cascade) {
|
||||
wmMenuEntry *tmp;
|
||||
tmp = findEntry(entry->cascade, tag);
|
||||
if (tmp)
|
||||
return tmp;
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wmHandleMenuEvents(WMAppContext *app, XEvent *event)
|
||||
static void wmHandleMenuEvents(WMAppContext * app, XEvent * event)
|
||||
{
|
||||
wmMenuEntry *entry;
|
||||
wmMenuEntry *entry;
|
||||
|
||||
switch (event->xclient.data.l[1]) {
|
||||
case wmSelectItem:
|
||||
entry = findEntry(app->main_menu, event->xclient.data.l[2]);
|
||||
if (entry && entry->callback) {
|
||||
(*entry->callback)(entry->clientData, event->xclient.data.l[2],
|
||||
event->xclient.data.l[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (event->xclient.data.l[1]) {
|
||||
case wmSelectItem:
|
||||
entry = findEntry(app->main_menu, event->xclient.data.l[2]);
|
||||
if (entry && entry->callback) {
|
||||
(*entry->callback) (entry->clientData, event->xclient.data.l[2], event->xclient.data.l[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
WMProcessEvent(WMAppContext *app, XEvent *event)
|
||||
int WMProcessEvent(WMAppContext * app, XEvent * event)
|
||||
{
|
||||
int proc=False;
|
||||
if (!_XA_WINDOWMAKER_MENU) {
|
||||
_XA_WINDOWMAKER_MENU = XInternAtom(app->dpy, "_WINDOWMAKER_MENU",
|
||||
False);
|
||||
}
|
||||
switch (event->type) {
|
||||
case ClientMessage:
|
||||
if (event->xclient.format == 32
|
||||
&& event->xclient.message_type == _XA_WINDOWMAKER_MENU
|
||||
&& event->xclient.window == app->main_window) {
|
||||
wmHandleMenuEvents(app, event);
|
||||
proc = True;
|
||||
}
|
||||
}
|
||||
return proc;
|
||||
int proc = False;
|
||||
if (!_XA_WINDOWMAKER_MENU) {
|
||||
_XA_WINDOWMAKER_MENU = XInternAtom(app->dpy, "_WINDOWMAKER_MENU", False);
|
||||
}
|
||||
switch (event->type) {
|
||||
case ClientMessage:
|
||||
if (event->xclient.format == 32
|
||||
&& event->xclient.message_type == _XA_WINDOWMAKER_MENU
|
||||
&& event->xclient.window == app->main_window) {
|
||||
wmHandleMenuEvents(app, event);
|
||||
proc = True;
|
||||
}
|
||||
}
|
||||
return proc;
|
||||
}
|
||||
|
||||
|
||||
392
wmlib/menu.c
392
wmlib/menu.c
@@ -29,228 +29,210 @@
|
||||
#include "app.h"
|
||||
#include "menu.h"
|
||||
|
||||
|
||||
WMMenu*
|
||||
WMMenuCreate(WMAppContext *app, char *title)
|
||||
WMMenu *WMMenuCreate(WMAppContext * app, char *title)
|
||||
{
|
||||
wmMenu *menu;
|
||||
wmMenu *menu;
|
||||
|
||||
if (strlen(title)>255)
|
||||
return NULL;
|
||||
if (strlen(title) > 255)
|
||||
return NULL;
|
||||
|
||||
menu = malloc(sizeof(wmMenu));
|
||||
if (!menu)
|
||||
return NULL;
|
||||
menu = malloc(sizeof(wmMenu));
|
||||
if (!menu)
|
||||
return NULL;
|
||||
|
||||
menu->appcontext = app;
|
||||
menu->parent = NULL;
|
||||
menu->title = title;
|
||||
menu->entries = NULL;
|
||||
menu->first = NULL;
|
||||
menu->appcontext = app;
|
||||
menu->parent = NULL;
|
||||
menu->title = title;
|
||||
menu->entries = NULL;
|
||||
menu->first = NULL;
|
||||
|
||||
menu->realized = False;
|
||||
menu->code = app->last_menu_tag++;
|
||||
menu->realized = False;
|
||||
menu->code = app->last_menu_tag++;
|
||||
|
||||
menu->entryline = malloc(strlen(title)+32);
|
||||
menu->entryline2 = malloc(32);
|
||||
if (!menu->entryline || !menu->entryline2) {
|
||||
if (menu->entryline)
|
||||
free(menu->entryline);
|
||||
free(menu);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(menu->entryline, "%i %i %s", wmBeginMenu, menu->code, title);
|
||||
sprintf(menu->entryline2, "%i %i", wmEndMenu, menu->code);
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
WMMenuAddItem(WMMenu *menu, char *text, WMMenuAction action,
|
||||
void *clientData, WMFreeFunction freedata, char *rtext)
|
||||
{
|
||||
wmMenuEntry *entry;
|
||||
|
||||
/* max size of right side text */
|
||||
if (rtext && strlen(rtext)>4)
|
||||
return -1;
|
||||
|
||||
/* max size of menu text */
|
||||
if (strlen(text)>255)
|
||||
return -1;
|
||||
|
||||
entry = malloc(sizeof(wmMenuEntry));
|
||||
if (!entry)
|
||||
return -1;
|
||||
|
||||
entry->entryline = malloc(strlen(text)+100);
|
||||
if (!entry->entryline) {
|
||||
free(menu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (menu->entries)
|
||||
entry->order = menu->entries->order + 1;
|
||||
else {
|
||||
entry->order = 0;
|
||||
menu->first = entry;
|
||||
}
|
||||
entry->next = NULL;
|
||||
entry->prev = menu->entries;
|
||||
if (menu->entries)
|
||||
menu->entries->next = entry;
|
||||
menu->entries = entry;
|
||||
|
||||
entry->menu = menu;
|
||||
entry->text = text;
|
||||
entry->shortcut = rtext;
|
||||
entry->callback = action;
|
||||
entry->clientData = clientData;
|
||||
entry->free = freedata;
|
||||
entry->tag = menu->appcontext->last_menu_tag++;
|
||||
entry->cascade = NULL;
|
||||
entry->enabled = True;
|
||||
|
||||
|
||||
if (!rtext)
|
||||
sprintf(entry->entryline, "%i %i %i %i %s", wmNormalItem,
|
||||
menu->code, entry->tag, True, text);
|
||||
else
|
||||
sprintf(entry->entryline, "%i %i %i %i %s %s", wmDoubleItem,
|
||||
menu->code, entry->tag, True, rtext, text);
|
||||
return entry->tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
WMMenuAddSubmenu(WMMenu *menu, char *text, WMMenu *submenu)
|
||||
{
|
||||
wmMenuEntry *entry;
|
||||
|
||||
/* max size of menu text */
|
||||
if (strlen(text)>255)
|
||||
return -1;
|
||||
|
||||
entry = malloc(sizeof(wmMenuEntry));
|
||||
if (!entry)
|
||||
return -1;
|
||||
|
||||
entry->entryline = malloc(strlen(text)+100);
|
||||
if (!entry->entryline) {
|
||||
free(menu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (menu->entries)
|
||||
entry->order = menu->entries->order + 1;
|
||||
else {
|
||||
entry->order = 0;
|
||||
menu->first = entry;
|
||||
}
|
||||
entry->next = NULL;
|
||||
entry->prev = menu->entries;
|
||||
if (menu->entries)
|
||||
menu->entries->next = entry;
|
||||
menu->entries = entry;
|
||||
entry->menu = menu;
|
||||
entry->text = text;
|
||||
entry->shortcut = NULL;
|
||||
entry->callback = NULL;
|
||||
entry->clientData = NULL;
|
||||
entry->tag = menu->appcontext->last_menu_tag++;
|
||||
entry->cascade = submenu;
|
||||
entry->enabled = True;
|
||||
|
||||
sprintf(entry->entryline, "%i %i %i %i %i %s", wmSubmenuItem,
|
||||
menu->code, entry->tag, True, submenu->code, text);
|
||||
return entry->tag;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
countItems(WMMenu *menu)
|
||||
{
|
||||
wmMenuEntry *entry = menu->first;
|
||||
int c;
|
||||
|
||||
c = 1;
|
||||
while (entry) {
|
||||
c++;
|
||||
if (entry->cascade) {
|
||||
c += countItems(entry->cascade);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
c++;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
addItems(char **slist, int *index, WMMenu *menu)
|
||||
{
|
||||
wmMenuEntry *entry = menu->first;
|
||||
|
||||
slist[(*index)++] = menu->entryline;
|
||||
while (entry) {
|
||||
slist[(*index)++] = entry->entryline;
|
||||
if (entry->cascade) {
|
||||
addItems(slist, index, entry->cascade);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
slist[(*index)++] = menu->entryline2;
|
||||
}
|
||||
|
||||
|
||||
static Atom
|
||||
getatom(Display *dpy)
|
||||
{
|
||||
static Atom atom=0;
|
||||
|
||||
if (atom==0) {
|
||||
atom = XInternAtom(dpy, WMMENU_PROPNAME, False);
|
||||
}
|
||||
return atom;
|
||||
menu->entryline = malloc(strlen(title) + 32);
|
||||
menu->entryline2 = malloc(32);
|
||||
if (!menu->entryline || !menu->entryline2) {
|
||||
if (menu->entryline)
|
||||
free(menu->entryline);
|
||||
free(menu);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(menu->entryline, "%i %i %s", wmBeginMenu, menu->code, title);
|
||||
sprintf(menu->entryline2, "%i %i", wmEndMenu, menu->code);
|
||||
return menu;
|
||||
}
|
||||
|
||||
int
|
||||
WMRealizeMenus(WMAppContext *app)
|
||||
WMMenuAddItem(WMMenu * menu, char *text, WMMenuAction action,
|
||||
void *clientData, WMFreeFunction freedata, char *rtext)
|
||||
{
|
||||
int i, count;
|
||||
char **slist;
|
||||
XTextProperty text_prop;
|
||||
wmMenuEntry *entry;
|
||||
|
||||
if (!app->main_menu)
|
||||
return False;
|
||||
/* max size of right side text */
|
||||
if (rtext && strlen(rtext) > 4)
|
||||
return -1;
|
||||
|
||||
/* first count how many menu items there are */
|
||||
count = countItems(app->main_menu);
|
||||
if (count==0)
|
||||
return True;
|
||||
/* max size of menu text */
|
||||
if (strlen(text) > 255)
|
||||
return -1;
|
||||
|
||||
count++;
|
||||
slist = malloc(count*sizeof(char*));
|
||||
if (!slist) {
|
||||
return False;
|
||||
}
|
||||
entry = malloc(sizeof(wmMenuEntry));
|
||||
if (!entry)
|
||||
return -1;
|
||||
|
||||
slist[0] = "WMMenu 0";
|
||||
i = 1;
|
||||
addItems(slist, &i, app->main_menu);
|
||||
entry->entryline = malloc(strlen(text) + 100);
|
||||
if (!entry->entryline) {
|
||||
free(menu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!XStringListToTextProperty(slist, i, &text_prop)) {
|
||||
free(slist);
|
||||
return False;
|
||||
}
|
||||
free(slist);
|
||||
XSetTextProperty(app->dpy, app->main_window, &text_prop,
|
||||
getatom(app->dpy));
|
||||
if (menu->entries)
|
||||
entry->order = menu->entries->order + 1;
|
||||
else {
|
||||
entry->order = 0;
|
||||
menu->first = entry;
|
||||
}
|
||||
entry->next = NULL;
|
||||
entry->prev = menu->entries;
|
||||
if (menu->entries)
|
||||
menu->entries->next = entry;
|
||||
menu->entries = entry;
|
||||
|
||||
XFree(text_prop.value);
|
||||
entry->menu = menu;
|
||||
entry->text = text;
|
||||
entry->shortcut = rtext;
|
||||
entry->callback = action;
|
||||
entry->clientData = clientData;
|
||||
entry->free = freedata;
|
||||
entry->tag = menu->appcontext->last_menu_tag++;
|
||||
entry->cascade = NULL;
|
||||
entry->enabled = True;
|
||||
|
||||
return True;
|
||||
if (!rtext)
|
||||
sprintf(entry->entryline, "%i %i %i %i %s", wmNormalItem, menu->code, entry->tag, True, text);
|
||||
else
|
||||
sprintf(entry->entryline, "%i %i %i %i %s %s", wmDoubleItem,
|
||||
menu->code, entry->tag, True, rtext, text);
|
||||
return entry->tag;
|
||||
}
|
||||
|
||||
int WMMenuAddSubmenu(WMMenu * menu, char *text, WMMenu * submenu)
|
||||
{
|
||||
wmMenuEntry *entry;
|
||||
|
||||
/* max size of menu text */
|
||||
if (strlen(text) > 255)
|
||||
return -1;
|
||||
|
||||
entry = malloc(sizeof(wmMenuEntry));
|
||||
if (!entry)
|
||||
return -1;
|
||||
|
||||
entry->entryline = malloc(strlen(text) + 100);
|
||||
if (!entry->entryline) {
|
||||
free(menu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (menu->entries)
|
||||
entry->order = menu->entries->order + 1;
|
||||
else {
|
||||
entry->order = 0;
|
||||
menu->first = entry;
|
||||
}
|
||||
entry->next = NULL;
|
||||
entry->prev = menu->entries;
|
||||
if (menu->entries)
|
||||
menu->entries->next = entry;
|
||||
menu->entries = entry;
|
||||
entry->menu = menu;
|
||||
entry->text = text;
|
||||
entry->shortcut = NULL;
|
||||
entry->callback = NULL;
|
||||
entry->clientData = NULL;
|
||||
entry->tag = menu->appcontext->last_menu_tag++;
|
||||
entry->cascade = submenu;
|
||||
entry->enabled = True;
|
||||
|
||||
sprintf(entry->entryline, "%i %i %i %i %i %s", wmSubmenuItem,
|
||||
menu->code, entry->tag, True, submenu->code, text);
|
||||
return entry->tag;
|
||||
}
|
||||
|
||||
static int countItems(WMMenu * menu)
|
||||
{
|
||||
wmMenuEntry *entry = menu->first;
|
||||
int c;
|
||||
|
||||
c = 1;
|
||||
while (entry) {
|
||||
c++;
|
||||
if (entry->cascade) {
|
||||
c += countItems(entry->cascade);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
c++;
|
||||
return c;
|
||||
}
|
||||
|
||||
static void addItems(char **slist, int *index, WMMenu * menu)
|
||||
{
|
||||
wmMenuEntry *entry = menu->first;
|
||||
|
||||
slist[(*index)++] = menu->entryline;
|
||||
while (entry) {
|
||||
slist[(*index)++] = entry->entryline;
|
||||
if (entry->cascade) {
|
||||
addItems(slist, index, entry->cascade);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
slist[(*index)++] = menu->entryline2;
|
||||
}
|
||||
|
||||
static Atom getatom(Display * dpy)
|
||||
{
|
||||
static Atom atom = 0;
|
||||
|
||||
if (atom == 0) {
|
||||
atom = XInternAtom(dpy, WMMENU_PROPNAME, False);
|
||||
}
|
||||
return atom;
|
||||
}
|
||||
|
||||
int WMRealizeMenus(WMAppContext * app)
|
||||
{
|
||||
int i, count;
|
||||
char **slist;
|
||||
XTextProperty text_prop;
|
||||
|
||||
if (!app->main_menu)
|
||||
return False;
|
||||
|
||||
/* first count how many menu items there are */
|
||||
count = countItems(app->main_menu);
|
||||
if (count == 0)
|
||||
return True;
|
||||
|
||||
count++;
|
||||
slist = malloc(count * sizeof(char *));
|
||||
if (!slist) {
|
||||
return False;
|
||||
}
|
||||
|
||||
slist[0] = "WMMenu 0";
|
||||
i = 1;
|
||||
addItems(slist, &i, app->main_menu);
|
||||
|
||||
if (!XStringListToTextProperty(slist, i, &text_prop)) {
|
||||
free(slist);
|
||||
return False;
|
||||
}
|
||||
free(slist);
|
||||
XSetTextProperty(app->dpy, app->main_window, &text_prop, getatom(app->dpy));
|
||||
|
||||
XFree(text_prop.value);
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user