~ubuntu-branches/ubuntu/wily/wdm/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-1.28-7/src/wdmLogin/Login.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2011-07-19 20:05:52 UTC
  • Revision ID: james.westby@ubuntu.com-20110719200552-5pwzpzru3asczkzp
Tags: 1.28-7
* QA upload
* Changed build-dependency on libjpeg62-dev to libjpeg-dev (closes: #634642)
* Migrate to source format 3.0 (quilt):
  - add debian/source/format
  - drop build-dependency on dpatch
  - drop all patching/unpatching from debian/rules
  - drop touching of configure since quilt patching now does it for us

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * wdm - WINGs display manager
 
3
 * Copyright (C) 2003, 2004 Alexey Voinov <voins@voins.program.ru>
 
4
 * Copyright (C) 1998 Gene Czarcinski
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 *
 
20
 * Login.c: draw login panel and interact with user.
 
21
 */
 
22
 
 
23
#include <wdmconfig.h>
 
24
#include <wdmlib.h>
 
25
#include <wdmLogin.h>
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <unistd.h>
 
29
#include <string.h>
 
30
#include <ctype.h>
 
31
#include <signal.h>
 
32
#ifdef HAVE_SYS_PARAM_H
 
33
#include <sys/param.h>
 
34
#endif
 
35
#include <sys/types.h>
 
36
#include <sys/stat.h>
 
37
#include <fcntl.h>
 
38
#include <X11/Xlib.h>
 
39
#include <X11/xpm.h>
 
40
#include <X11/keysym.h>
 
41
#include <X11/cursorfont.h>
 
42
#ifdef HAVE_XINERAMA
 
43
#include <X11/extensions/Xinerama.h>
 
44
#endif
 
45
/* temporary hack {{{ */
 
46
#include <WINGs/WINGsP.h>
 
47
/* }}} */
 
48
#include <limits.h>
 
49
#include <locale.h>
 
50
#include <time.h>
 
51
 
 
52
/*###################################################################*/
 
53
 
 
54
/** Global Variables and Constants **/
 
55
 
 
56
#define FOREVER 1
 
57
 
 
58
WMRect screen;
 
59
static int help_heigth = 140;
 
60
static int text_width = 150, text_heigth = 26;
 
61
 
 
62
static char displayArgDefault[] = "";
 
63
static char *displayArg = displayArgDefault;
 
64
 
 
65
/*###################################################################*/
 
66
 
 
67
static int WmDefUser = False;   /* default username */
 
68
 
 
69
static char *helpArg = NULL;
 
70
static char *HelpMsg = N_("no help available.");
 
71
 
 
72
/*###################################################################*/
 
73
 
 
74
typedef struct LoginPanel
 
75
{
 
76
        WMScreen *scr;
 
77
        WMWindow *win;
 
78
        WMFrame *winF1;
 
79
        WMFrame *logoF1, *logoF2;
 
80
        WMLabel *logoL;
 
81
        WMFrame *authF;
 
82
        WMLabel *welcomeMsg1, *welcomeMsg2;
 
83
        WMTextField *entryText;
 
84
        WMLabel *entryLabel;
 
85
        WMFrame *msgF;
 
86
        WMLabel *msgL;
 
87
        int msgFlag;
 
88
        WMFrame *wmF;
 
89
        WMPopUpButton *wmBtn;
 
90
        WMFrame *exitF;
 
91
        WMPopUpButton *exitBtn;
 
92
        WMFrame *cmdF;
 
93
        WMButton *helpBtn;
 
94
        WMButton *startoverBtn;
 
95
        WMButton *goBtn;
 
96
        WMFrame *helpF;
 
97
        WMScrollView *helpSV;
 
98
        WMFrame *helpTextF;
 
99
        WMLabel *helpTextL;
 
100
        KeyCode retkey;
 
101
        KeyCode tabkey;
 
102
}
 
103
LoginPanel;
 
104
 
 
105
static LoginPanel *panel = NULL;
 
106
 
 
107
/*###################################################################*/
 
108
 
 
109
static int LoginSwitch = False;
 
110
static char *LoginName = NULL;
 
111
static char *LoginPswd = NULL;
 
112
 
 
113
static int OptionCode = 0;
 
114
static char *ExitStr[] = { N_("Login"), N_("Reboot"), N_("Halt"),
 
115
#ifdef WITH_EXITLOGIN
 
116
        N_("ExitLogin"),
 
117
#endif
 
118
        NULL };
 
119
 
 
120
static char *ExitFailStr[] = { N_("Login failed"), N_("Reboot failed"),
 
121
        N_("Halt failed"),
 
122
#ifdef WITH_EXITLOGIN
 
123
        N_("ExitLogin failed"),
 
124
#endif
 
125
        NULL };
 
126
 
 
127
static int WmOptionCode = 0;
 
128
static char WmDefault[] = "wmaker:afterstep:xsession";
 
129
static char *WmArg = WmDefault;
 
130
static char **WmStr = NULL;
 
131
 
 
132
static char *logoArg = NULL;
 
133
static char *bgArg = NULL;
 
134
static char *bgOption = NULL;
 
135
static int animate = False;
 
136
static int smoothScale = True;
 
137
static char *configFile = NULL;
 
138
static int wdm_fd = 1;
 
139
#ifdef HAVE_XINERAMA
 
140
static int xinerama_head = 0;
 
141
#endif
 
142
 
 
143
static WDMLoginConfig *cfg;
 
144
 
 
145
static int exit_request = 0;
 
146
 
 
147
char *ProgName = "Login";
 
148
 
 
149
char *
 
150
read_help_file(int handle)
 
151
{
 
152
        char *HelpText = NULL;
 
153
        struct stat s;
 
154
 
 
155
        if(fstat(handle, &s) == 0)
 
156
        {
 
157
                HelpText = wmalloc(s.st_size + 1);
 
158
                if(read(handle, HelpText, s.st_size) == -1)
 
159
                {
 
160
                        WDMError("%s - read_help_file(): can't read %s\n",
 
161
                                ProgName, helpArg);
 
162
                        wfree(HelpText);
 
163
                        return NULL;
 
164
                }
 
165
                HelpText[s.st_size] = '\0';
 
166
        }
 
167
        else
 
168
                WDMError("%s - read_help_file(): can't stat %s\n",
 
169
                        ProgName, helpArg);
 
170
 
 
171
        return HelpText;
 
172
}
 
173
 
 
174
char *
 
175
parse_helpArg(void)
 
176
{
 
177
        int handle;
 
178
        char *HelpText = NULL;
 
179
        char *defaultHelpText = NULL;
 
180
 
 
181
        /* a good default value, even in case of errors */
 
182
        defaultHelpText = wstrconcat("wdm --- " PACKAGE_VERSION "\n\n\n\n\n",
 
183
                                     _(HelpMsg));
 
184
        HelpText = defaultHelpText;
 
185
 
 
186
        if(helpArg)
 
187
        {
 
188
                if((handle = open(helpArg, O_RDONLY)) == -1)
 
189
                {
 
190
                        WDMError("%s - parse_helpArg(): can't open %s\n",
 
191
                                ProgName, helpArg);
 
192
                        return defaultHelpText;
 
193
                }
 
194
 
 
195
                if((HelpText = read_help_file(handle)) != NULL)
 
196
                        wfree(defaultHelpText);
 
197
 
 
198
                close(handle);
 
199
        }
 
200
 
 
201
        return HelpText;
 
202
}
 
203
 
 
204
/*###################################################################*/
 
205
 
 
206
void
 
207
wAbort()                        /* for WINGs compatibility */
 
208
{
 
209
        WDMPanic("%s - wAbort from WINGs\n", ProgName);
 
210
}
 
211
 
 
212
/*###################################################################*/
 
213
 
 
214
/*** pipe I/O routines ***/
 
215
 
 
216
/** The following code was adapted from out.c by Tom Rothamel */
 
217
 
 
218
/* This file is Copyright 1998 Tom Rothamel. It's under the Gnu Public   *
 
219
 * license, see the file COPYING for details.                            */
 
220
 
 
221
void
 
222
writeuc(int fd, unsigned char c)
 
223
{
 
224
        write(fd, &c, sizeof(unsigned char));
 
225
}
 
226
 
 
227
void
 
228
writestring(int fd, char *string)
 
229
{
 
230
        int len;
 
231
 
 
232
        len = strlen(string);
 
233
        if(len > 255)
 
234
                len = 255;
 
235
 
 
236
        writeuc(fd, (unsigned char) len);
 
237
        write(fd, string, len);
 
238
}
 
239
 
 
240
 
 
241
/*** communicate authentication information ***/
 
242
 
 
243
static void
 
244
OutputAuth(char *user, char *pswd)
 
245
{
 
246
        writestring(wdm_fd, user ? user : "");
 
247
        writestring(wdm_fd, pswd ? pswd : "");
 
248
 
 
249
        if(OptionCode == 0)
 
250
        {
 
251
                if(WmOptionCode == 0)
 
252
                        writeuc(wdm_fd, 0);     /* end of data */
 
253
                else
 
254
                {
 
255
                        writeuc(wdm_fd, 1);
 
256
                        writestring(wdm_fd, WmStr[WmOptionCode]);
 
257
                        writeuc(wdm_fd, 0);     /* end of data */
 
258
                }
 
259
        }
 
260
        else
 
261
        {
 
262
                writeuc(wdm_fd, OptionCode + 1);
 
263
                writestring(wdm_fd, ExitStr[OptionCode]);
 
264
                writeuc(wdm_fd, 0);     /* end of data */
 
265
        }
 
266
        return;
 
267
}
 
268
 
 
269
/*###################################################################*/
 
270
 
 
271
static void
 
272
SetupWm()
 
273
{
 
274
        int i = 0, n = 0;
 
275
        char *ptr = WmArg;
 
276
 
 
277
        /* count number of items, skip empty items.
 
278
           n = number of items - 1 */
 
279
        while(*ptr)
 
280
                if(*ptr++ == ':' && *ptr != ':' && *ptr)
 
281
                        ++n;
 
282
        /* reserve one position fo NULL pointer, one for 'NoChange'
 
283
           and one for 'FailSafe' */
 
284
        WmStr = (char **) malloc(sizeof(char *) * (n + 4));
 
285
        WmStr[i++] = N_("NoChange");
 
286
 
 
287
        if(strcasecmp(WmArg, "none") != 0)      /* we explicitly don't want any
 
288
                                                   choice */
 
289
        {
 
290
                ptr = WmArg;
 
291
                while(*ptr)
 
292
                {
 
293
                        while(*ptr == ':')
 
294
                                ++ptr;
 
295
                        if(!*ptr)
 
296
                                break;
 
297
                        WmStr[i++] = ptr;
 
298
                        while(*ptr != ':' && *ptr)
 
299
                                ++ptr;
 
300
                        if(!*ptr)
 
301
                                break;
 
302
                        *ptr++ = '\0';
 
303
                }
 
304
                WmStr[i++] = N_("failsafe");
 
305
        }
 
306
        WmStr[i] = NULL;
 
307
}
 
308
 
 
309
 
 
310
static void
 
311
LoginArgs(int argc, char *argv[])
 
312
{
 
313
        int c;
 
314
 
 
315
 
 
316
        while((c = getopt(argc, argv, "asb:d:h:l:uw:c:x:f:")) != -1)
 
317
        {
 
318
                switch (c)
 
319
                {
 
320
                case 'a':
 
321
                        animate = True;
 
322
                        break;
 
323
                case 's':
 
324
                        smoothScale = False;
 
325
                        break;
 
326
                case 'd':       /* display */
 
327
                        displayArg = optarg;
 
328
                        break;
 
329
                case 'h':       /* helpfile */
 
330
                        helpArg = optarg;
 
331
                        break;
 
332
                case 'l':       /* logo */
 
333
                        logoArg = optarg;
 
334
                        break;
 
335
                case 'u':       /* default user */
 
336
                        WmDefUser = True;
 
337
                        break;
 
338
                case 'w':       /* wm list */
 
339
                        WmArg = optarg;
 
340
                        break;
 
341
                case 'b':       /* background */
 
342
                        bgArg = optarg;
 
343
                        break;
 
344
                case 'c':       /* configfile */
 
345
                        configFile = optarg;
 
346
                        break;
 
347
                case 'f':       /* filedescriptor for wdm comm.*/
 
348
                        wdm_fd = strtol(optarg, NULL, 0);
 
349
                        if(wdm_fd < 1) wdm_fd = 1;
 
350
                        break;
 
351
#ifdef HAVE_XINERAMA
 
352
                case 'x':       /* xinerama head */
 
353
                        xinerama_head = strtol(optarg, NULL, 0);
 
354
                        break;
 
355
#endif
 
356
                default:
 
357
                        WDMError("bad option: %c\n", c);
 
358
                        break;
 
359
                }
 
360
        }
 
361
}
 
362
 
 
363
/*###################################################################*/
 
364
 
 
365
/* write error message to the panel */
 
366
 
 
367
static void
 
368
ClearMsgs(LoginPanel * panel)
 
369
{
 
370
        WMSetFrameRelief(panel->msgF, WRFlat);
 
371
        WMSetFrameTitle(panel->msgF, "");
 
372
        WMSetLabelText(panel->msgL, "");
 
373
        panel->msgFlag = False;
 
374
        XFlush(WMScreenDisplay(panel->scr));
 
375
}
 
376
 
 
377
static void
 
378
PrintErrMsg(LoginPanel * panel, char *msg)
 
379
{
 
380
        int i, x;
 
381
        struct timespec timeReq;
 
382
 
 
383
        XSynchronize(WMScreenDisplay(panel->scr), True);
 
384
        ClearMsgs(panel);
 
385
        WMSetFrameRelief(panel->msgF, WRGroove);
 
386
        WMSetFrameTitle(panel->msgF, _("ERROR"));
 
387
        WMSetLabelText(panel->msgL, msg);
 
388
        panel->msgFlag = True;
 
389
        XFlush(WMScreenDisplay(panel->scr));
 
390
 
 
391
        /* shake the panel like Login.app */
 
392
        if(animate)
 
393
        {
 
394
                timeReq.tv_sec = 0;
 
395
                timeReq.tv_nsec = 15;
 
396
                for(i = 0; i < 3; i++)
 
397
                {
 
398
                        for(x = 2; x <= 30; x += 10)
 
399
                        {
 
400
                                WMMoveWidget(panel->win,
 
401
                                        cfg->geometry.pos.x + x,
 
402
                                        cfg->geometry.pos.y);
 
403
                                nanosleep(&timeReq, NULL);
 
404
                        }
 
405
                        for(x = 30; x >= -30; x -= 10)
 
406
                        {
 
407
                                WMMoveWidget(panel->win,
 
408
                                        cfg->geometry.pos.x + x,
 
409
                                        cfg->geometry.pos.y);
 
410
                                nanosleep(&timeReq, NULL);
 
411
                        }
 
412
                        for(x = -28; x <= 0; x += 10)
 
413
                        {
 
414
                                WMMoveWidget(panel->win,
 
415
                                        cfg->geometry.pos.x + x,
 
416
                                        cfg->geometry.pos.y);
 
417
                                nanosleep(&timeReq, NULL);
 
418
                        }
 
419
                        XFlush(WMScreenDisplay(panel->scr));
 
420
                }
 
421
        }
 
422
        XSynchronize(WMScreenDisplay(panel->scr), False);
 
423
}
 
424
 
 
425
/* write info message to panel */
 
426
 
 
427
static void
 
428
PrintInfoMsg(LoginPanel * panel, char *msg)
 
429
{
 
430
        XSynchronize(WMScreenDisplay(panel->scr), True);
 
431
        ClearMsgs(panel);
 
432
        WMSetLabelText(panel->msgL, msg);
 
433
        XFlush(WMScreenDisplay(panel->scr));
 
434
        panel->msgFlag = True;
 
435
        XSynchronize(WMScreenDisplay(panel->scr), False);
 
436
}
 
437
 
 
438
/*###################################################################*/
 
439
 
 
440
static void
 
441
init_pwdfield(char *pwd)
 
442
{
 
443
        WMSetTextFieldText(panel->entryText, pwd);
 
444
        WMSetTextFieldSecure(panel->entryText, True);
 
445
        WMSetLabelText(panel->entryLabel, _("Password:"));
 
446
}
 
447
 
 
448
static void
 
449
init_namefield(char *name)
 
450
{
 
451
        WMResizeWidget(panel->entryText, text_width, text_heigth);
 
452
        WMSetTextFieldText(panel->entryText, name);
 
453
        WMSetLabelText(panel->entryLabel, _("Login name:"));
 
454
        WMSetFocusToWidget(panel->entryText);
 
455
        WMSetTextFieldSecure(panel->entryText, False);
 
456
}
 
457
 
 
458
static void
 
459
InitializeLoginInput(LoginPanel * panel)
 
460
{
 
461
        LoginSwitch = False;
 
462
        if(LoginName)
 
463
                wfree(LoginName);
 
464
        LoginName = NULL;
 
465
        if(LoginPswd)
 
466
                wfree(LoginPswd);
 
467
        LoginPswd = NULL;
 
468
 
 
469
        init_namefield("");
 
470
}
 
471
 
 
472
static void
 
473
PerformLogin(LoginPanel * panel, int canexit)
 
474
{
 
475
        if(LoginSwitch == False)
 
476
        {
 
477
                if(LoginName)
 
478
                        wfree(LoginName);
 
479
                LoginName = WMGetTextFieldText(panel->entryText);
 
480
 
 
481
                if((LoginName[0] == '\0') && (WmDefUser == False))
 
482
                {
 
483
                        InitializeLoginInput(panel);
 
484
                        PrintErrMsg(panel, _("invalid name"));
 
485
                        return;
 
486
                }
 
487
 
 
488
                LoginSwitch = True;
 
489
 
 
490
                init_pwdfield(LoginPswd);
 
491
                return;
 
492
        }
 
493
        LoginSwitch = False;
 
494
        if(LoginPswd)
 
495
                wfree(LoginPswd);
 
496
        LoginPswd = WMGetTextFieldText(panel->entryText);
 
497
 
 
498
        if(canexit == False)
 
499
        {
 
500
                init_namefield(LoginName);
 
501
                return;
 
502
        }
 
503
 
 
504
        init_namefield("");
 
505
        if(OptionCode == 0)
 
506
                PrintInfoMsg(panel, _("validating"));
 
507
        else
 
508
                PrintInfoMsg(panel, _("exiting"));
 
509
 
 
510
        OutputAuth(LoginName, LoginPswd);
 
511
}
 
512
 
 
513
/*###################################################################*/
 
514
 
 
515
/* Actions */
 
516
 
 
517
 
 
518
static void
 
519
goPressed(WMWidget * self, LoginPanel * panel)
 
520
{
 
521
        if(OptionCode == 0)
 
522
        {
 
523
                if(LoginSwitch == False)
 
524
                {
 
525
                        PerformLogin(panel, True);
 
526
                        if(LoginSwitch == False)
 
527
                                return;
 
528
                }
 
529
                PerformLogin(panel, True);
 
530
                return;
 
531
        }
 
532
        if(LoginSwitch == True)
 
533
        {
 
534
                if(LoginPswd)
 
535
                        wfree(LoginPswd);
 
536
                LoginPswd = WMGetTextFieldText(panel->entryText);
 
537
                WMSetTextFieldText(panel->entryText, "");
 
538
        }
 
539
        PrintInfoMsg(panel, _("exiting"));
 
540
        OutputAuth(LoginName, LoginPswd);
 
541
}
 
542
 
 
543
static void
 
544
startoverPressed(WMWidget * self, LoginPanel * panel)
 
545
{
 
546
        ClearMsgs(panel);
 
547
        InitializeLoginInput(panel);
 
548
}
 
549
 
 
550
static void
 
551
helpPressed(WMWidget * self, LoginPanel * panel)
 
552
{
 
553
        static Bool helpshown = False;
 
554
        if(!helpshown)
 
555
        {
 
556
                helpshown = True;
 
557
                WMSetButtonText(panel->helpBtn, _("Close Help"));
 
558
                WMResizeWidget(panel->win, WMWidgetWidth(panel->win),
 
559
                                WMWidgetHeight(panel->win) + help_heigth);
 
560
        }
 
561
        else
 
562
        {
 
563
                helpshown = False;
 
564
                WMSetButtonText(panel->helpBtn, _("Help"));
 
565
                WMResizeWidget(panel->win, WMWidgetWidth(panel->win),
 
566
                                WMWidgetHeight(panel->win) - help_heigth);
 
567
        }
 
568
}
 
569
 
 
570
static void
 
571
changeWm(WMWidget * self, LoginPanel * panel)
 
572
{
 
573
        WmOptionCode = WMGetPopUpButtonSelectedItem(self);
 
574
        WMSetFocusToWidget(panel->entryText);
 
575
}
 
576
 
 
577
static void
 
578
changeOption(WMPopUpButton * self, LoginPanel * panel)
 
579
{
 
580
        int item;
 
581
 
 
582
        item = WMGetPopUpButtonSelectedItem(self);
 
583
        OptionCode = item;
 
584
        WMSetFocusToWidget(panel->entryText);
 
585
}
 
586
 
 
587
static void
 
588
handleKeyPress(XEvent * event, void *clientData)
 
589
{
 
590
        LoginPanel *panel = (LoginPanel *) clientData;
 
591
 
 
592
        if(panel->msgFlag)
 
593
        {
 
594
                ClearMsgs(panel);
 
595
        }
 
596
        if(event->xkey.keycode == panel->retkey)
 
597
        {
 
598
                PerformLogin(panel, True);
 
599
        }
 
600
        else if(event->xkey.keycode == panel->tabkey)
 
601
        {
 
602
                PerformLogin(panel, False);
 
603
        }
 
604
}
 
605
 
 
606
/*###################################################################*/
 
607
 
 
608
/* create and destroy our panel */
 
609
 
 
610
static void
 
611
CreateLogo(LoginPanel * panel)
 
612
{
 
613
        RImage *image1, *image2;
 
614
        WMPixmap *pixmap;
 
615
        RColor gray;
 
616
        RContext *context;
 
617
        unsigned w = 200, h = 130;
 
618
        float ratio = 1.;
 
619
 
 
620
        panel->logoF1 = WMCreateFrame(panel->winF1);
 
621
        WMSetFrameRelief(panel->logoF1, WRSunken);
 
622
        WMSetFrameTitlePosition(panel->logoF1, WTPAtTop);
 
623
        WMMoveWidget(panel->logoF1, 15, 18);
 
624
        WMResizeWidget(panel->logoF1, 206, 136);
 
625
 
 
626
        panel->logoF2 = WMCreateFrame(panel->logoF1);
 
627
        WMSetFrameRelief(panel->logoF2, WRSunken);
 
628
        WMSetFrameTitlePosition(panel->logoF2, WTPAtTop);
 
629
        WMMoveWidget(panel->logoF2, 1, 1);
 
630
        WMResizeWidget(panel->logoF2, 204, 134);
 
631
 
 
632
        panel->logoL = WMCreateLabel(panel->logoF2);
 
633
        WMMoveWidget(panel->logoL, 2, 2);
 
634
        WMResizeWidget(panel->logoL, 200, 130);
 
635
        WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
 
636
 
 
637
        context = WMScreenRContext(panel->scr);
 
638
        image1 = NULL;
 
639
        if(logoArg != NULL)
 
640
        {
 
641
                image1 = RLoadImage(context, logoArg, 0);
 
642
        }
 
643
        if(image1 == NULL)
 
644
        {
 
645
                RColor first, second;
 
646
                first.red = 0xae;
 
647
                first.green = 0xaa;
 
648
                first.blue = 0xc0;
 
649
                second.red = 0xae;
 
650
                second.green = 0xaa;
 
651
                second.blue = 0xae;
 
652
                image1 = RRenderGradient(200, 300, &first, &second, RDiagonalGradient);
 
653
        }
 
654
        if(image1 == NULL)
 
655
                return;
 
656
 
 
657
#if 0
 
658
        WDMDebug("width=%i,heigth=%i\n", image1->width, image1->height);
 
659
#endif
 
660
                if(image1->width > 200)
 
661
        {                       /* try to keep the aspect ratio */
 
662
                ratio = (float) 200. / (float) image1->width;
 
663
                h = (int) ((float) image1->height * ratio);
 
664
        }
 
665
#if 0
 
666
        WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
 
667
#endif
 
668
                if(image1->height > 130)
 
669
        {
 
670
                if(h > 130)
 
671
                {
 
672
                        ratio = (float) 130. / (float) h;
 
673
                        w = (int) ((float) w * ratio);
 
674
                        h = 130;
 
675
                }
 
676
        }
 
677
#if 0
 
678
        WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
 
679
#endif
 
680
                /* if image is too small, do not reallly resize since this looks bad */
 
681
                /* the image will be centered */
 
682
        if((image1->width < 200) && (image1->height < 130))
 
683
        {
 
684
                w = image1->width;
 
685
                h = image1->height;
 
686
        }
 
687
        /* last check in case the above logic is faulty */
 
688
        if(w > 200)
 
689
                w = 200;
 
690
        if(h > 130)
 
691
                h = 130;
 
692
#if 0
 
693
        WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
 
694
#endif
 
695
        if(smoothScale)
 
696
                image2 = RSmoothScaleImage(image1, w, h);
 
697
        else
 
698
                image2 = RScaleImage(image1, w, h);
 
699
 
 
700
        RReleaseImage(image1);
 
701
        if(image2 == NULL)
 
702
                return;
 
703
        gray.red = 0xae;
 
704
        gray.green = 0xaa;
 
705
        gray.blue = 0xae;
 
706
        RCombineImageWithColor(image2, &gray);
 
707
        pixmap = WMCreatePixmapFromRImage(panel->scr, image2, 0);
 
708
        RReleaseImage(image2);
 
709
 
 
710
        if(pixmap == NULL)
 
711
        {
 
712
                WDMError("unable to load pixmap\n");
 
713
                return;
 
714
        }
 
715
        WMSetLabelImage(panel->logoL, pixmap);
 
716
        WMReleasePixmap(pixmap);
 
717
 
 
718
}
 
719
 
 
720
static void
 
721
CreateAuthFrame(LoginPanel * panel)
 
722
{
 
723
        char str[128] = "?";
 
724
        WMFont *font = NULL;
 
725
        int y;
 
726
 
 
727
        panel->authF = WMCreateFrame(panel->winF1);
 
728
        WMSetFrameRelief(panel->authF, WRGroove);
 
729
        WMSetFrameTitlePosition(panel->authF, WTPAtTop);
 
730
        WMSetFrameTitle(panel->authF, _("Login Authentication"));
 
731
        WMMoveWidget(panel->authF, (WMWidgetWidth(panel->win) - 290), 10);
 
732
        WMResizeWidget(panel->authF, 275, 120);
 
733
 
 
734
        gethostname(str, 127);
 
735
 
 
736
        y = 20;
 
737
        panel->welcomeMsg1 = WMCreateLabel(panel->authF);
 
738
        WMResizeWidget(panel->welcomeMsg1, 255, 26);
 
739
        WMSetLabelText(panel->welcomeMsg1, _("Welcome to"));
 
740
        WMMoveWidget(panel->welcomeMsg1, 11, y);
 
741
        y += 26;
 
742
        WMSetLabelTextAlignment(panel->welcomeMsg1, WACenter);
 
743
        font = WMBoldSystemFontOfSize(panel->scr, 18);
 
744
        if(font)
 
745
        {
 
746
                WMSetLabelFont(panel->welcomeMsg1, font);
 
747
                WMReleaseFont(font);
 
748
        }
 
749
 
 
750
        panel->welcomeMsg2 = WMCreateLabel(panel->authF);
 
751
        WMResizeWidget(panel->welcomeMsg2, 255, 26);
 
752
        WMMoveWidget(panel->welcomeMsg2, 11, y);
 
753
        WMSetLabelText(panel->welcomeMsg2, str);
 
754
        WMSetLabelTextAlignment(panel->welcomeMsg2, WACenter);
 
755
        y = 18;
 
756
        if(strlen(str) > 20)
 
757
                y = 16;
 
758
        if(strlen(str) > 30)
 
759
                y = 14;
 
760
        if(strlen(str) > 34)
 
761
                y = 12;
 
762
        if(strlen(str) > 40)
 
763
                y = 10;
 
764
        font = WMBoldSystemFontOfSize(panel->scr, y);
 
765
        if(font)
 
766
        {
 
767
                WMSetLabelFont(panel->welcomeMsg2, font);
 
768
                WMReleaseFont(font);
 
769
        }
 
770
 
 
771
        y = 84;
 
772
 
 
773
        panel->entryLabel = WMCreateLabel(panel->authF);
 
774
        WMMoveWidget(panel->entryLabel, 10, y);
 
775
        WMResizeWidget(panel->entryLabel, 100, 26);
 
776
        font = WMBoldSystemFontOfSize(panel->scr, 14);
 
777
        if(font)
 
778
        {
 
779
                WMSetLabelFont(panel->entryLabel, font);
 
780
                WMReleaseFont(font);
 
781
        }
 
782
        WMSetLabelText(panel->entryLabel, _("Login name:"));
 
783
        WMSetLabelTextAlignment(panel->entryLabel, WARight);
 
784
 
 
785
        panel->entryText = WMCreateTextField(panel->authF);
 
786
        WMMoveWidget(panel->entryText, 115, y);
 
787
        WMResizeWidget(panel->entryText, text_width, text_heigth);
 
788
        WMSetTextFieldText(panel->entryText, "");
 
789
        WMSetTextFieldSecure(panel->entryText, False);
 
790
}
 
791
 
 
792
static void
 
793
CreateMsgsFrames(LoginPanel * panel)
 
794
{
 
795
        WMFont *font;
 
796
 
 
797
        panel->msgF = WMCreateFrame(panel->winF1);
 
798
        WMSetFrameRelief(panel->msgF, WRFlat);
 
799
        WMSetFrameTitlePosition(panel->msgF, WTPAtBottom);
 
800
        WMMoveWidget(panel->msgF, (WMWidgetWidth(panel->win) - 290), 136);
 
801
        WMResizeWidget(panel->msgF, 275, 40);
 
802
        WMSetFrameTitle(panel->msgF, "");
 
803
 
 
804
        panel->msgL = WMCreateLabel(panel->msgF);
 
805
        WMResizeWidget(panel->msgL, 260, 26);
 
806
        WMMoveWidget(panel->msgL, 5, 2);
 
807
        font = WMBoldSystemFontOfSize(panel->scr, 14);
 
808
        if(font)
 
809
        {
 
810
                WMSetLabelFont(panel->msgL, font);
 
811
                WMReleaseFont(font);
 
812
        }
 
813
        WMSetLabelText(panel->msgL, "");
 
814
        WMSetLabelTextAlignment(panel->msgL, WARight);
 
815
 
 
816
}
 
817
 
 
818
static void
 
819
CreatePopups(LoginPanel * panel)
 
820
{
 
821
        int i;
 
822
 
 
823
        panel->wmF = WMCreateFrame(panel->winF1);
 
824
        WMSetFrameRelief(panel->wmF, WRGroove);
 
825
        WMSetFrameTitlePosition(panel->wmF, WTPAtTop);
 
826
        WMSetFrameTitle(panel->wmF, _("Start WM"));
 
827
        WMMoveWidget(panel->wmF, 13, 178);
 
828
        WMResizeWidget(panel->wmF, 118, 45);
 
829
 
 
830
        panel->wmBtn = WMCreatePopUpButton(panel->wmF);
 
831
        WMMoveWidget(panel->wmBtn, 4, 15);
 
832
        WMResizeWidget(panel->wmBtn, 110, 25);
 
833
        WMSetPopUpButtonAction(panel->wmBtn, (WMAction *) changeWm, panel);
 
834
        i = 0;
 
835
        while(WmStr[i] != NULL)
 
836
        {
 
837
                WMAddPopUpButtonItem(panel->wmBtn, _(WmStr[i]));
 
838
                i++;
 
839
        }
 
840
 
 
841
        panel->exitF = WMCreateFrame(panel->winF1);
 
842
        WMSetFrameRelief(panel->exitF, WRGroove);
 
843
        WMSetFrameTitlePosition(panel->exitF, WTPAtTop);
 
844
        WMSetFrameTitle(panel->exitF, _("Options"));
 
845
        WMMoveWidget(panel->exitF, 134, 178);
 
846
        WMResizeWidget(panel->exitF, 98, 45);
 
847
 
 
848
        panel->exitBtn = WMCreatePopUpButton(panel->exitF);
 
849
        WMMoveWidget(panel->exitBtn, 4, 15);
 
850
        WMResizeWidget(panel->exitBtn, 90, 25);
 
851
        WMSetPopUpButtonAction(panel->exitBtn, (WMAction *) changeOption,
 
852
                               panel);
 
853
        i = 0;
 
854
        while(ExitStr[i] != NULL)
 
855
        {
 
856
                WMAddPopUpButtonItem(panel->exitBtn, _(ExitStr[i]));
 
857
                i++;
 
858
        }
 
859
}
 
860
 
 
861
static void
 
862
CreateButtons(LoginPanel * panel)
 
863
{
 
864
        int i;
 
865
 
 
866
        panel->cmdF = WMCreateFrame(panel->winF1);
 
867
        WMSetFrameRelief(panel->cmdF, WRFlat);
 
868
        WMSetFrameTitlePosition(panel->cmdF, WTPAtTop);
 
869
        WMMoveWidget(panel->cmdF, (WMWidgetWidth(panel->win) - 290), 185);
 
870
        WMResizeWidget(panel->cmdF, 282, 38);
 
871
 
 
872
        i = 3;
 
873
        panel->helpBtn = WMCreateCommandButton(panel->cmdF);
 
874
        WMSetButtonAction(panel->helpBtn, (WMAction *) helpPressed, panel);
 
875
        WMMoveWidget(panel->helpBtn, i, 8);
 
876
        WMSetButtonText(panel->helpBtn, _("Help"));
 
877
        WMResizeWidget(panel->helpBtn, 80, 25);
 
878
 
 
879
        i += 96;
 
880
        panel->startoverBtn = WMCreateCommandButton(panel->cmdF);
 
881
        WMSetButtonAction(panel->startoverBtn, (WMAction *) startoverPressed,
 
882
                          panel);
 
883
        WMMoveWidget(panel->startoverBtn, i, 8);
 
884
        WMSetButtonText(panel->startoverBtn, _("Start Over"));
 
885
        WMResizeWidget(panel->startoverBtn, 80, 25);
 
886
 
 
887
        i += 96;
 
888
        panel->goBtn = WMCreateCommandButton(panel->cmdF);
 
889
        WMSetButtonAction(panel->goBtn, (WMAction *) goPressed, panel);
 
890
        WMMoveWidget(panel->goBtn, i, 8);
 
891
        WMSetButtonText(panel->goBtn, _("Go!"));
 
892
        WMResizeWidget(panel->goBtn, 80, 25);
 
893
}
 
894
 
 
895
static void
 
896
CreateHelpFrames(LoginPanel * panel)
 
897
{
 
898
        int height;
 
899
        char *HelpText = NULL;
 
900
 
 
901
        panel->helpF = WMCreateFrame(panel->win);
 
902
        WMSetFrameRelief(panel->helpF, WRRaised);
 
903
        WMMoveWidget(panel->helpF, 0, WMWidgetHeight(panel->win));
 
904
        WMResizeWidget(panel->helpF, WMWidgetWidth(panel->win), help_heigth);
 
905
 
 
906
        panel->helpSV = WMCreateScrollView(panel->helpF);
 
907
        WMResizeWidget(panel->helpSV,
 
908
                        (WMWidgetWidth(panel->win) - 10), (help_heigth - 10));
 
909
        WMMoveWidget(panel->helpSV, 5, 5);
 
910
        WMSetScrollViewRelief(panel->helpSV, WRSunken);
 
911
        WMSetScrollViewHasVerticalScroller(panel->helpSV, True);
 
912
        WMSetScrollViewHasHorizontalScroller(panel->helpSV, False);
 
913
        WMSetScrollViewLineScroll(panel->helpSV, 12);
 
914
 
 
915
        HelpText = parse_helpArg();
 
916
 
 
917
        panel->helpTextF = WMCreateFrame(panel->helpF);
 
918
        WMSetFrameRelief(panel->helpTextF, WRFlat);
 
919
        panel->helpTextL = WMCreateLabel(panel->helpTextF);
 
920
        WMSetLabelTextAlignment(panel->helpTextL, WALeft);
 
921
 
 
922
        height = W_GetTextHeight(WMDefaultSystemFont(panel->scr),
 
923
                        HelpText, (WMWidgetWidth(panel->win) - 60), True) + 10;
 
924
 
 
925
        WMResizeWidget(panel->helpTextF,
 
926
                        (WMWidgetWidth(panel->win) - 50), height);
 
927
        WMMoveWidget(panel->helpTextL, 2, 1);
 
928
        WMResizeWidget(panel->helpTextL,
 
929
                        (WMWidgetWidth(panel->win) - 60), height - 5);
 
930
 
 
931
        WMSetLabelText(panel->helpTextL, HelpText);
 
932
        WMSetLabelWraps(panel->helpTextL, True);
 
933
 
 
934
        wfree(HelpText);
 
935
}
 
936
 
 
937
static LoginPanel *
 
938
CreateLoginPanel(WMScreen *scr, WDMLoginConfig *cfg)
 
939
{
 
940
        LoginPanel *panel;
 
941
 
 
942
        panel = malloc(sizeof(LoginPanel));
 
943
        if(!panel)
 
944
                return NULL;
 
945
        memset(panel, 0, sizeof(LoginPanel));
 
946
        panel->scr = scr;
 
947
 
 
948
        /* basic window and frames */
 
949
 
 
950
        panel->win = WMCreateWindow(scr, ProgName);
 
951
        WMResizeWidget(panel->win,
 
952
                        cfg->geometry.size.width, cfg->geometry.size.height);
 
953
 
 
954
        panel->winF1 = WMCreateFrame(panel->win);
 
955
        WMResizeWidget(panel->winF1,
 
956
                        cfg->geometry.size.width, cfg->geometry.size.height);
 
957
        WMSetFrameRelief(panel->winF1, WRRaised);
 
958
 
 
959
        CreateAuthFrame(panel);
 
960
 
 
961
        CreateLogo(panel);
 
962
 
 
963
        CreatePopups(panel);
 
964
 
 
965
        CreateButtons(panel);
 
966
 
 
967
        CreateMsgsFrames(panel);
 
968
 
 
969
        CreateHelpFrames(panel);
 
970
 
 
971
        WMRealizeWidget(panel->win);
 
972
        WMMapSubwidgets(panel->win);
 
973
 
 
974
        WMMapSubwidgets(panel->winF1);
 
975
        WMMapSubwidgets(panel->logoF1);
 
976
        WMMapSubwidgets(panel->logoF2);
 
977
        WMMapSubwidgets(panel->authF);
 
978
        WMMapSubwidgets(panel->wmF);
 
979
        WMMapSubwidgets(panel->exitF);
 
980
        WMMapSubwidgets(panel->cmdF);
 
981
        WMMapSubwidgets(panel->msgF);
 
982
        WMMapSubwidgets(panel->helpF);
 
983
        WMMapWidget(panel->helpF);
 
984
        WMMapSubwidgets(panel->helpSV);
 
985
        WMMapSubwidgets(panel->helpTextF);
 
986
        WMSetScrollViewContentView(panel->helpSV,
 
987
                                   WMWidgetView(panel->helpTextF));
 
988
 
 
989
        WMSetPopUpButtonSelectedItem(panel->wmBtn, 0);
 
990
        WMSetPopUpButtonSelectedItem(panel->exitBtn, 0);
 
991
 
 
992
        panel->msgFlag = False;
 
993
 
 
994
        return panel;
 
995
}
 
996
 
 
997
static void
 
998
DestroyLoginPanel(LoginPanel * panel)
 
999
{
 
1000
        int width, height;
 
1001
        struct timespec timeReq;
 
1002
 
 
1003
        /* roll up the window before destroying it */
 
1004
        if(animate)
 
1005
        {
 
1006
                timeReq.tv_sec = 0;
 
1007
                timeReq.tv_nsec = 400;
 
1008
                XSynchronize(WMScreenDisplay(panel->scr), True);        /* slow things up */
 
1009
                for(width = WMWidgetWidth(panel->win) - 2,
 
1010
                        height = WMWidgetHeight(panel->win) - 1;
 
1011
                    (height > 0 && width > 0); height -= 15, width -= 30)
 
1012
                {
 
1013
                        WMResizeWidget(panel->win, width, height);
 
1014
                        nanosleep(&timeReq, NULL);
 
1015
                }
 
1016
                XSynchronize(WMScreenDisplay(panel->scr), False);
 
1017
        }
 
1018
        WMUnmapWidget(panel->win);
 
1019
        WMDestroyWidget(panel->win);
 
1020
        free(panel);
 
1021
}
 
1022
 
 
1023
/*###################################################################*/
 
1024
 
 
1025
/** set the background **/
 
1026
 
 
1027
static int
 
1028
parseBG()
 
1029
{
 
1030
        char *tmp;
 
1031
 
 
1032
        if(bgArg == NULL)
 
1033
                return 0;
 
1034
        tmp = strchr(bgArg, ':');
 
1035
        if(tmp == NULL)
 
1036
                return 0;
 
1037
        *tmp = '\0';
 
1038
        bgOption = tmp + 1;
 
1039
        while(*bgOption == ' ')
 
1040
                bgOption++;
 
1041
        if(*bgOption == '\0')
 
1042
                return 0;
 
1043
        tmp = bgArg;
 
1044
        while(*tmp != '\0')
 
1045
        {
 
1046
                *tmp = tolower(*tmp);
 
1047
                tmp++;
 
1048
        }
 
1049
        if(strcmp(bgArg, "pixmap") == 0)
 
1050
                return 1;
 
1051
        if(strcmp(bgArg, "solid") == 0)
 
1052
                return 2;
 
1053
        if(strcmp(bgArg, "hgradient") == 0)
 
1054
                return 3;
 
1055
        if(strcmp(bgArg, "vgradient") == 0)
 
1056
                return 4;
 
1057
        if(strcmp(bgArg, "dgradient") == 0)
 
1058
                return 5;
 
1059
        return 0;
 
1060
}
 
1061
 
 
1062
static RImage *
 
1063
loadBGpixmap(RContext * rcontext)
 
1064
{
 
1065
        RImage *image, *tmp;
 
1066
 
 
1067
        image = RLoadImage(rcontext, bgOption, 0);
 
1068
        if(image == NULL)
 
1069
        {
 
1070
                WDMError("%s could not load bg image %s\n",
 
1071
                        ProgName, bgOption);
 
1072
                return NULL;
 
1073
        }
 
1074
        tmp = RScaleImage(image, screen.size.width, screen.size.height);
 
1075
        if(tmp == NULL)
 
1076
        {
 
1077
                WDMError("%s could not resize bg image %s\n",
 
1078
                        ProgName, bgOption);
 
1079
                RReleaseImage(image);
 
1080
                return NULL;
 
1081
        }
 
1082
        RReleaseImage(image);
 
1083
        return tmp;
 
1084
}
 
1085
 
 
1086
static RColor **
 
1087
allocmem(int num)
 
1088
{
 
1089
        RColor **colors = NULL;
 
1090
        int i;
 
1091
 
 
1092
        colors = malloc(sizeof(RColor *) * (num + 1));
 
1093
        for(i = 0; i < num; i++)
 
1094
        {
 
1095
                colors[i] = malloc(sizeof(RColor));
 
1096
        }
 
1097
        colors[i] = NULL;
 
1098
        return colors;
 
1099
}
 
1100
 
 
1101
static void
 
1102
freemem(int num, RColor ** colors)
 
1103
{
 
1104
        int i;
 
1105
 
 
1106
        for(i = 0; i < num; i++)
 
1107
        {
 
1108
                free(colors[i]);
 
1109
        }
 
1110
        free(colors);
 
1111
}
 
1112
 
 
1113
static RImage *
 
1114
createBGcolor(WMScreen * scr, RContext * rcontext, char *str, int style)
 
1115
{
 
1116
        RImage *image;
 
1117
        RColor **colors = NULL;
 
1118
        XColor color;
 
1119
        int num_colors = 0;
 
1120
        int i;
 
1121
        char *tmp, *colorstr;
 
1122
 
 
1123
        colorstr = str;
 
1124
        while(*colorstr)
 
1125
        {
 
1126
                num_colors++;
 
1127
                tmp = strchr(colorstr, ',');
 
1128
                if(tmp == NULL)
 
1129
                        colorstr = str + strlen(str);
 
1130
                else
 
1131
                        colorstr = tmp + 1;
 
1132
        }
 
1133
        if(num_colors == 0)
 
1134
                return NULL;
 
1135
        colors = allocmem(num_colors);
 
1136
        tmp = str;
 
1137
        for(i = 0; i < num_colors; i++)
 
1138
        {
 
1139
                colorstr = tmp;
 
1140
                tmp = strchr(tmp, ',');
 
1141
                if(tmp != NULL)
 
1142
                {
 
1143
                        *tmp = '\0';
 
1144
                        tmp++;
 
1145
                }
 
1146
                else
 
1147
                        tmp = colorstr + strlen(colorstr);
 
1148
                if(!XParseColor
 
1149
                   (WMScreenDisplay(scr), rcontext->cmap, colorstr, &color))
 
1150
                {
 
1151
                        WDMError("could not parse color \"%s\"\n",
 
1152
                                colorstr);
 
1153
                        freemem(num_colors, colors);
 
1154
                        return NULL;
 
1155
                }
 
1156
                colors[i]->red = color.red >> 8;
 
1157
                colors[i]->green = color.green >> 8;
 
1158
                colors[i]->blue = color.blue >> 8;
 
1159
        }
 
1160
        image = RRenderMultiGradient(screen.size.width, screen.size.height,
 
1161
                                     colors, style);
 
1162
        freemem(num_colors, colors);
 
1163
        return image;
 
1164
}
 
1165
 
 
1166
static void
 
1167
setBG(WMScreen * scr)
 
1168
{
 
1169
        Window root_window;
 
1170
        int cpc = 4, render_mode = RBestMatchRendering, default_depth = 8;
 
1171
        RContextAttributes rattr;
 
1172
        RContext *rcontext;
 
1173
        RImage *image;
 
1174
        XColor defcolor;
 
1175
        Pixmap pixmap;
 
1176
 
 
1177
        /* if not specified or none, then skip setting background */
 
1178
        /* user can still set background via other means */
 
1179
        if(bgArg == NULL)
 
1180
                return;
 
1181
        if(strcasecmp(bgArg, "none") == 0)
 
1182
                return;
 
1183
 
 
1184
        /* use of scr->rootWin is temporary hack */
 
1185
        root_window = scr->rootWin;
 
1186
        default_depth = WMScreenDepth(scr);
 
1187
        if(default_depth <= 8)
 
1188
                render_mode = RDitheredRendering;
 
1189
        rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
 
1190
        rattr.render_mode = render_mode;
 
1191
        rattr.colors_per_channel = cpc;
 
1192
        /* use of scr->screen is temporary hack */
 
1193
        rcontext = RCreateContext(WMScreenDisplay(scr), scr->screen, &rattr);
 
1194
        if(rcontext == NULL)
 
1195
        {
 
1196
                WDMError("%s could not initialize "
 
1197
                        "graphics library context: %s\n",
 
1198
                        ProgName, RMessageForError(RErrorCode));
 
1199
                return;
 
1200
        }
 
1201
 
 
1202
        defcolor.pixel = 0L;    /* default=black */
 
1203
 
 
1204
        switch (parseBG())
 
1205
        {
 
1206
        case 1:
 
1207
                image = loadBGpixmap(rcontext);
 
1208
                break;
 
1209
        case 2:
 
1210
                image = createBGcolor(scr, rcontext, bgOption, RGRD_HORIZONTAL);
 
1211
                break;
 
1212
        case 3:
 
1213
                image = createBGcolor(scr, rcontext, bgOption, RGRD_HORIZONTAL);
 
1214
                break;
 
1215
        case 4:
 
1216
                image = createBGcolor(scr, rcontext, bgOption, RGRD_VERTICAL);
 
1217
                break;
 
1218
        case 5:
 
1219
                image = createBGcolor(scr, rcontext, bgOption, RGRD_DIAGONAL);
 
1220
                break;
 
1221
        default:
 
1222
                image = NULL;
 
1223
                break;
 
1224
        }
 
1225
        if(image == NULL)
 
1226
        {
 
1227
                XSetWindowBackground(WMScreenDisplay(scr), root_window, 0L);
 
1228
                XClearWindow(WMScreenDisplay(scr), root_window);
 
1229
                XFlush(WMScreenDisplay(scr));
 
1230
                return;
 
1231
        }
 
1232
        RConvertImage(rcontext, image, &pixmap);
 
1233
        RReleaseImage(image);
 
1234
        XSetWindowBackgroundPixmap(WMScreenDisplay(scr), root_window, pixmap);
 
1235
        XClearWindow(WMScreenDisplay(scr), root_window);
 
1236
        XFlush(WMScreenDisplay(scr));
 
1237
}
 
1238
 
 
1239
/*###################################################################*/
 
1240
 
 
1241
/* signal processing */
 
1242
 
 
1243
static void
 
1244
SignalUsr1(int ignored)         /* oops, an error */
 
1245
{
 
1246
        InitializeLoginInput(panel);
 
1247
        PrintErrMsg(panel, _(ExitFailStr[OptionCode]));
 
1248
        signal(SIGUSR1, SignalUsr1);
 
1249
}
 
1250
 
 
1251
static void
 
1252
SignalTerm(int ignored)         /* all done */
 
1253
{
 
1254
        exit_request = 1;       /* corrects some hanging problems, thanks to A. Kabaev */
 
1255
}
 
1256
 
 
1257
/*###################################################################*/
 
1258
 
 
1259
/*  M A I N  */
 
1260
 
 
1261
int
 
1262
main(int argc, char **argv)
 
1263
{
 
1264
        WMScreen *scr;
 
1265
        int xine_count;
 
1266
 
 
1267
#ifdef HAVE_XINERAMA
 
1268
        XineramaScreenInfo *xine;
 
1269
#endif
 
1270
 
 
1271
        ProgName = argv[0];
 
1272
 
 
1273
        setlocale(LC_ALL, "");
 
1274
 
 
1275
#ifdef I18N
 
1276
        if(getenv("NLSPATH"))
 
1277
                bindtextdomain("wdm", getenv("NLSPATH"));
 
1278
        else
 
1279
                bindtextdomain("wdm", NLSDIR);
 
1280
#if WINGS_H_VERSION >= 20040406
 
1281
        bind_textdomain_codeset("wdm", "UTF-8");
 
1282
#endif
 
1283
        textdomain("wdm");
 
1284
#endif
 
1285
 
 
1286
        animate = False;
 
1287
        LoginArgs(argc, argv);  /* process our args */
 
1288
 
 
1289
        cfg = LoadConfiguration(configFile);    /* load configs */
 
1290
        if(cfg)
 
1291
        {
 
1292
                printf("geometry: %ix%i+%i+%i\n",
 
1293
                                cfg->geometry.size.width,
 
1294
                                cfg->geometry.size.height,
 
1295
                                cfg->geometry.pos.x,
 
1296
                                cfg->geometry.pos.y);
 
1297
        }
 
1298
 
 
1299
        SetupWm();              /* and init the startup list */
 
1300
 
 
1301
        WMInitializeApplication(ProgName, &argc, argv);
 
1302
        scr = WMOpenScreen(displayArg);
 
1303
        if(!scr)
 
1304
        {
 
1305
                WDMPanic("could not initialize Screen\n");
 
1306
                exit(2);
 
1307
        }
 
1308
 
 
1309
#if WINGS_H_VERSION < 20040406
 
1310
        if(cfg->multibyte)
 
1311
                scr->useMultiByte = True;
 
1312
#endif
 
1313
 
 
1314
#ifdef USE_AA
 
1315
        if(cfg->aaenabled)
 
1316
        {
 
1317
                scr->antialiasedText = True;
 
1318
                scr->normalFont = WMSystemFontOfSize(scr,
 
1319
                                WINGsConfiguration.defaultFontSize);
 
1320
 
 
1321
                scr->boldFont = WMBoldSystemFontOfSize(scr, 
 
1322
                                WINGsConfiguration.defaultFontSize);
 
1323
 
 
1324
                if(!scr->boldFont)
 
1325
                        scr->boldFont = scr->normalFont;
 
1326
 
 
1327
                if(!scr->normalFont)
 
1328
                {
 
1329
                        WDMError("could not load any fonts.");
 
1330
                        exit(2);
 
1331
                }
 
1332
        }
 
1333
#endif
 
1334
        if(cfg->animations)
 
1335
                animate = True;
 
1336
 
 
1337
        screen.pos.x = 0;
 
1338
        screen.pos.y = 0;
 
1339
        screen.size.width = WMScreenWidth(scr);
 
1340
        screen.size.height = WMScreenHeight(scr);
 
1341
#ifdef HAVE_XINERAMA
 
1342
        if(XineramaIsActive(WMScreenDisplay(scr)))
 
1343
        {
 
1344
                xine = XineramaQueryScreens(WMScreenDisplay(scr), &xine_count);
 
1345
 
 
1346
                if(xine != NULL)
 
1347
                {
 
1348
                        if(xinerama_head < xine_count)
 
1349
                        {
 
1350
                                screen.pos.x = xine[xinerama_head].x_org;
 
1351
                                screen.pos.y = xine[xinerama_head].y_org;
 
1352
                                screen.size.width = xine[xinerama_head].width;
 
1353
                                screen.size.height = xine[xinerama_head].height;
 
1354
                        }
 
1355
                }
 
1356
        }
 
1357
#endif
 
1358
 
 
1359
        if(cfg->geometry.pos.x == INT_MIN || cfg->geometry.pos.y == INT_MIN)
 
1360
        {
 
1361
                cfg->geometry.pos.x = screen.pos.x +
 
1362
                        (screen.size.width - cfg->geometry.size.width)/2;
 
1363
                cfg->geometry.pos.y = screen.pos.y +
 
1364
                        (screen.size.height - cfg->geometry.size.height)/2;
 
1365
        }
 
1366
 
 
1367
        XSynchronize(WMScreenDisplay(scr), False);
 
1368
 
 
1369
        /* use of scr->rootWin is temporary hack */
 
1370
        XWarpPointer(WMScreenDisplay(scr), None,
 
1371
                     scr->rootWin,
 
1372
                     0, 0, 0, 0,
 
1373
                     (cfg->geometry.pos.x + (cfg->geometry.size.width - 10)),
 
1374
                     (cfg->geometry.pos.y + (cfg->geometry.size.height - 10)));
 
1375
        /* use of scr->rootWin is temporary hack */
 
1376
        XDefineCursor(WMScreenDisplay(scr),
 
1377
                      scr->rootWin,
 
1378
                      XCreateFontCursor(WMScreenDisplay(scr),
 
1379
                                        XC_top_left_arrow));
 
1380
 
 
1381
        setBG(scr);
 
1382
 
 
1383
 
 
1384
        panel = CreateLoginPanel(scr, cfg);
 
1385
        WMSetWindowTitle(panel->win, ProgName);
 
1386
        /* the following Resize and the one following the Move fake out WINGs */
 
1387
        /* so that the move is not visible */
 
1388
        WMResizeWidget(panel->win, 1, 1);
 
1389
        WMMapWidget(panel->win);
 
1390
        WMSetWindowTitle(panel->win, ProgName);
 
1391
        WMMoveWidget(panel->win, cfg->geometry.pos.x, cfg->geometry.pos.y);
 
1392
        WMResizeWidget(panel->win, cfg->geometry.size.width, cfg->geometry.size.height);
 
1393
        WMSetFocusToWidget(panel->entryText);
 
1394
        XSetInputFocus(WMScreenDisplay(scr), WMWidgetXID(panel->win),
 
1395
                       RevertToParent, CurrentTime);
 
1396
        panel->retkey = XKeysymToKeycode(WMScreenDisplay(scr), XK_Return);
 
1397
        panel->tabkey = XKeysymToKeycode(WMScreenDisplay(scr), XK_Tab);
 
1398
 
 
1399
        WMCreateEventHandler(WMWidgetView(panel->entryText), KeyPressMask,
 
1400
                             handleKeyPress, panel);
 
1401
 
 
1402
        exit_request = 0;
 
1403
        signal(SIGUSR1, SignalUsr1);
 
1404
        signal(SIGTERM, SignalTerm);
 
1405
        signal(SIGINT, SignalTerm);
 
1406
        signal(SIGPIPE, SIG_DFL);
 
1407
 
 
1408
        while(!exit_request)
 
1409
        {
 
1410
                XEvent event;
 
1411
                WMNextEvent(WMScreenDisplay(scr), &event);
 
1412
                WMHandleEvent(&event);
 
1413
        }
 
1414
        DestroyLoginPanel(panel);
 
1415
 
 
1416
        return 0;
 
1417
}