-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.c
146 lines (129 loc) · 3.33 KB
/
menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
xrus - keyboard switcher/indicator
Copyright (c) 1996 Alexander V. Lukyanov
This is free software with no warranty.
See COPYING for details.
*/
#include <config.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#if TK!=TK_NONE
#if TK==TK_MOTIF
# include <Xm/Xm.h>
# include <Xm/RowColumn.h>
# include <Xm/PushB.h>
# include <Xm/Separator.h>
# include <Xm/CascadeB.h>
#elif TK==TK_XAW
# include <X11/Xaw/SimpleMenu.h>
# include <X11/Xaw/MenuButton.h>
# include <X11/Xaw/Command.h>
# include <X11/Xaw/Form.h>
# include <X11/Xaw/SmeBSB.h>
# include <X11/Xaw/SmeLine.h>
#endif
#include "xrus.h"
#include "menu.h"
#include "props.h"
#include "altmap.h"
Widget menu;
Widget menus[2]={0,0};
enum
{
LOCK,
PROPS,
EXIT
};
static
void menu_item_cb(Widget w,XtPointer closure,XtPointer call_data)
{
switch((int)closure)
{
case LOCK:
LockScreen();
break;
case PROPS:
PropsPopup();
break;
case EXIT:
cleanup();
XtDestroyApplicationContext(app_context);
app_context=NULL;
break;
}
}
static
XtCallbackRec menu_cb[]=
{
{menu_item_cb,0},
{NULL}
};
static
void popup_create(int n)
{
if((menu=menus[n])!=NULL)
return;
#if TK==TK_MOTIF
{
Widget altmap_menu;
menu=menus[n]=XmCreatePopupMenu(switch_button[n],"menu",NULL,0);
menu_cb[0].closure=(XtPointer)LOCK;
XtVaCreateManagedWidget("lock",xmPushButtonWidgetClass,menu,XmNactivateCallback,menu_cb,NULL);
menu_cb[0].closure=(XtPointer)PROPS;
XtVaCreateManagedWidget("props",xmPushButtonWidgetClass,menu,XmNactivateCallback,menu_cb,NULL);
altmap_menu=CreateAltMapMenu(menu,AppData.altMaps);
if(altmap_menu)
{
XtVaCreateManagedWidget("altmap",xmCascadeButtonWidgetClass,menu,
XmNsubMenuId,altmap_menu,
NULL);
}
XtVaCreateManagedWidget("line",xmSeparatorWidgetClass,menu,NULL);
menu_cb[0].closure=(XtPointer)EXIT;
XtVaCreateManagedWidget("exit",xmPushButtonWidgetClass,menu,XmNactivateCallback,menu_cb,NULL);
}
#elif TK==TK_XAW
menu=menus[n]=XtCreatePopupShell("menu",simpleMenuWidgetClass,switch_button[n],NULL,0);
{
static XtTranslations trans=None;
if(trans==None)
trans=XtParseTranslationTable(
"<Btn3Down>: XawPositionSimpleMenu(menu)"
" MenuPopup(menu)");
XtOverrideTranslations(switch_button[n],trans);
}
menu_cb[0].closure=(XtPointer)EXIT;
XtVaCreateManagedWidget("exit",smeBSBObjectClass,menu,XtNcallback,menu_cb,NULL);
XtVaCreateManagedWidget("line",smeLineObjectClass,menu,NULL);
CreateAltMapMenu(menu,AppData.altMaps);
XtVaCreateManagedWidget("line",smeLineObjectClass,menu,NULL);
menu_cb[0].closure=(XtPointer)LOCK;
XtVaCreateManagedWidget("lock",smeBSBObjectClass,menu,XtNcallback,menu_cb,NULL);
menu_cb[0].closure=(XtPointer)PROPS;
XtVaCreateManagedWidget("props",smeBSBObjectClass,menu,XtNcallback,menu_cb,NULL);
#else
# error bad TK
#endif
}
static
void popup_menu(XEvent *ev)
{
#if TK==TK_MOTIF
XmMenuPosition(menu,&(ev->xbutton));
XtManageChild(menu);
#endif
}
void XrusMenuCreate()
{
popup_create(0);
popup_create(1);
}
void XrusMenuPopup(Widget w,XEvent *ev,String *params, Cardinal *num_params)
{
popup_create(w==switch_button[1]);
popup_menu(ev);
}
#else /* TK_NONE */
void XrusMenuPopup(Widget w,XEvent *e,String *p, Cardinal *n) {}
#endif