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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
#if !defined( lint ) && !defined( SABER )
static const char sccsid[] = "@(#)xmlock.c 4.08 98/02/18 xlockmore";
#endif
/*-
* xmlock.c - main file for xmlock, the gui interface to xlock.
*
* Copyright (c) 1996 by Charles Vidal
*
* See xlock.c for copying information.
*
* Revision History:
* Nov-96: Continual minor improvements by Charles Vidal and David Bagley.
* Oct-96: written.
*/
/*-
XmLock Problems
1. Allowing only one in -inroot. Need a way to kill it.
2. XLock resources need to be read and used to set initial values.
3. Integer and floating point and string input.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/signal.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define HAVE_UNISTD_H 1
#endif /* HAVE_CONFIG_H */
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef VMS
#include <descrip.h>
#include <lib$routines.h>
#endif
/* #include <Xm/XmAll.h> Does not work on my version of Lesstif */
#include <Xm/PanedW.h>
#include <Xm/RowColumn.h>
#include <Xm/ToggleB.h>
#include <Xm/List.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#if USE_XMU
#include <X11/Xmu/Editres.h>
#endif
#include "bitmaps/m-xlock.xbm" /* icon bitmap */
/* like an enum */
#define LAUNCH 0
#define ROOT 1
#define WINDOW 2
#define EXIT 3
/* number of buttons, toggles, and string options */
#define PUSHBUTTONS 4
#define TOGGLES 9
#define OPTIONS 8
#define XLOCK "xlock"
#define WINDOW_WIDTH 160
#define WINDOW_HEIGHT 100
#define WINDOW_GEOMETRY "160x100"
/* extern variable */
extern char *c_Options[OPTIONS];
extern Widget Menuoption;
static pid_t numberprocess = -1; /* PID of xlock */
extern void Setup_Option(Widget MenuBar);
/* Widget */
Widget toplevel;
static Widget Labelxlock;
static Widget ScrolledListModes, PushButtons[PUSHBUTTONS], Toggles[TOGGLES];
/*Resource string */
#include "modes.h"
/* some resources of buttons and toggles not really good programming :( */
static char *r_PushButtons[PUSHBUTTONS] =
{
"Launch",
"In Root",
"In Window",
"Exit"
};
static char *r_Toggles[TOGGLES] =
{
"mono",
"nolock",
"remote",
"allowroot",
"enablesaver",
"allowaccess",
"grabmouse",
"echokeys",
"usefirst"
};
char *r_Options[OPTIONS] =
{
"username",
"password",
"info",
"validate",
"invalid",
"geometry",
"font",
"program"
};
static int numberinlist = 0;
/* CallBack */
static void
f_PushButtons(Widget w, XtPointer client_data, XtPointer call_data)
{
int i, n;
char command[500];
#ifdef VMS
int mask = 17;
struct dsc$descriptor_d vms_image;
#endif
(void) sprintf(command, "%s ", XLOCK);
/* booleans (+/-) options */
for (i = 0; i < TOGGLES; i++) {
if (XmToggleButtonGetState(Toggles[i])) {
(void) strcat(command, "-");
(void) strcat(command, r_Toggles[i]);
(void) strcat(command, " ");
}
}
for (i = 0; i < OPTIONS; i++)
if (c_Options[i] != NULL) {
(void) strcat(command, "-");
(void) strcat(command, r_Options[i]);
(void) strcat(command, " ");
(void) strcat(command, c_Options[i]);
(void) strcat(command, " ");
}
switch ((int) client_data) {
case LAUNCH:
/* the default value then nothing to do */
break;
case WINDOW:
(void) strcat(command, "-inwindow ");
break;
case ROOT:
(void) strcat(command, "-inroot ");
break;
case EXIT:
if (numberprocess != -1) {
(void) kill(numberprocess, SIGKILL);
(void) wait(&n);
}
exit(0);
break;
}
(void) strcat(command, "-mode ");
(void) strcat(command, LockProcs[numberinlist].cmdline_arg);
#ifdef VMS
vms_image.dsc$w_length = strlen(command);
vms_image.dsc$a_pointer = command;
vms_image.dsc$b_class = DSC$K_CLASS_S;
vms_image.dsc$b_dtype = DSC$K_DTYPE_T;
(void) printf("%s\n", command);
(void) lib$spawn(&vms_image, 0, 0, &mask);
#else
(void) strcat(command, " & ");
(void) printf("%s\n", command);
(void) system(command);
#endif
}
static void
f_ScrolledListModes(Widget w, XtPointer client_data, XtPointer call_data)
{
char numberwidget[50];
char str[50];
int n;
numberinlist = ((XmListCallbackStruct *) call_data)->item_position - 1;
(void) sprintf(numberwidget, "%ld", XtWindow(Labelxlock));
(void) sprintf(str, "%s", LockProcs[numberinlist].cmdline_arg);
if (numberprocess != -1) {
(void) kill(numberprocess, SIGKILL);
(void) wait(&n);
}
#ifdef VMS
#define FORK vfork
#else
#define FORK fork
#endif
if ((numberprocess = FORK()) == -1)
(void) fprintf(stderr, "Fork error\n");
else if (numberprocess == 0) {
(void) execlp(XLOCK, XLOCK, "-parent", numberwidget,
"-mode", str, "-geometry", WINDOW_GEOMETRY, "-delay", "100000",
"-nolock", "-inwindow", 0);
}
}
/* Setup Widget */
static void
Setup_Widget(Widget father)
{
Arg args[15];
int i, ac = 0;
Widget Row, PushButtonRow, TogglesRow, ModeLabel, SwitchLabel;
char string[160];
XmString label_str;
#define NUMPROCS 100 /* Greater than or equal to numprocs */
XmString TabXmStr[NUMPROCS];
ac = 0;
XtSetArg(args[ac], XmNrightAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNheight, WINDOW_HEIGHT);
ac++;
SwitchLabel = XmCreateLabel(father, "Switches", args, ac);
XtManageChild(SwitchLabel);
ac = 0;
XtSetArg(args[ac], XmNheight, WINDOW_HEIGHT);
ac++;
XtSetArg(args[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
ModeLabel = XmCreateLabel(father, "Modes", args, ac);
XtManageChild(ModeLabel);
ac = 0;
XtSetArg(args[ac], XmNwidth, WINDOW_WIDTH);
ac++;
XtSetArg(args[ac], XmNheight, WINDOW_HEIGHT);
ac++;
XtSetArg(args[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNleftAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg(args[ac], XmNleftWidget, ModeLabel);
ac++;
Labelxlock = XmCreateLabel(father, "Window", args, ac);
XtManageChild(Labelxlock);
/* buttons in the bottom */
ac = 0;
XtSetArg(args[ac], XmNorientation, XmHORIZONTAL);
ac++;
XtSetArg(args[ac], XmNrightAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_FORM);
ac++;
PushButtonRow = XmCreateRowColumn(father, "PushButtonRow", args, ac);
Menuoption = XmCreateMenuBar(PushButtonRow, "MenuBar", NULL, 0);
XtManageChild(Menuoption);
for (i = 0; i < PUSHBUTTONS; i++) {
ac = 0;
label_str = XmStringCreate(r_PushButtons[i], XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[ac], XmNlabelString, label_str);
ac++;
PushButtons[i] = XmCreatePushButton(PushButtonRow, r_PushButtons[i],
args, ac);
XmStringFree(label_str);
XtAddCallback(PushButtons[i], XmNactivateCallback, f_PushButtons,
(XtPointer) i);
XtManageChild(PushButtons[i]);
}
XtManageChild(PushButtonRow);
/* list and toggles in row like that (row(list)(TogglesRow(toggles...))) */
ac = 0;
XtSetArg(args[ac], XmNtopAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg(args[ac], XmNtopWidget, Labelxlock);
ac++;
XtSetArg(args[ac], XmNrightAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg(args[ac], XmNbottomWidget, PushButtonRow);
ac++;
XtSetArg(args[ac], XmNorientation, XmHORIZONTAL);
ac++;
Row = XmCreateRowColumn(father, "Row", args, ac);
if (numprocs > NUMPROCS) {
(void) printf("NUMPROCS too small should be at least %d\n", numprocs);
}
for (i = 0; i < numprocs; i++) {
(void) sprintf(string, "%-14s%s", LockProcs[i].cmdline_arg,
LockProcs[i].desc);
TabXmStr[i] = XmStringCreate(string, XmSTRING_DEFAULT_CHARSET);
}
ac = 0;
XtSetArg(args[ac], XmNitems, TabXmStr);
ac++;
XtSetArg(args[ac], XmNitemCount, numprocs);
ac++;
XtSetArg(args[ac], XmNvisibleItemCount, 10);
ac++;
ScrolledListModes = XmCreateScrolledList(Row, "ScrolledListModes",
args, ac);
XtAddCallback(ScrolledListModes, XmNbrowseSelectionCallback,
f_ScrolledListModes, NULL);
XtManageChild(ScrolledListModes);
TogglesRow = XmCreateRowColumn(Row, "TogglesRow", NULL, 0);
for (i = 0; i < TOGGLES; i++) {
ac = 0;
label_str = XmStringCreate(r_Toggles[i], XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[ac], XmNlabelString, label_str);
ac++;
Toggles[i] = XmCreateToggleButton(TogglesRow, r_Toggles[i], args, ac);
XmStringFree(label_str);
XtManageChild(Toggles[i]);
}
XtManageChild(TogglesRow);
XtManageChild(Row);
for (i = 0; i < numprocs; i++) {
XmStringFree(TabXmStr[i]);
}
}
int
main(int argc, char **argv)
{
Widget form;
Arg args[15];
/* PURIFY 4.0.1 on Solaris 2 reports an unitialized memory read on the next
line. */
toplevel = XtInitialize(argv[0], "XmLock", NULL, 0, &argc, argv);
XtSetArg(args[0], XtNiconPixmap,
XCreateBitmapFromData(XtDisplay(toplevel),
RootWindowOfScreen(XtScreen(toplevel)),
(char *) image_bits, image_width, image_height));
XtSetValues(toplevel, args, 1);
/* creation Widget */
/* PURIFY 4.0.1 on Solaris 2 reports an unitialized memory read on the next
line. */
form = XmCreateForm(toplevel, "Form", NULL, 0);
Setup_Widget(form);
Setup_Option(Menuoption);
XtManageChild(form);
XtRealizeWidget(toplevel);
#if USE_XMU
XtAddEventHandler(toplevel, (EventMask) 0, TRUE,
(XtEventHandler) _XEditResCheckMessages, NULL);
/* With this handler you can use editres */
#endif
XtMainLoop();
#ifdef VMS
return 1;
#else
return 0;
#endif
}
|