2
* wdm - WINGs display manager
3
* Copyright (C) 2003, 2004 Alexey Voinov <voins@voins.program.ru>
4
* Copyright (C) 1998 Gene Czarcinski
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.
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.
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
20
* Login.c: draw login panel and interact with user.
23
#include <wdmconfig.h>
32
#ifdef HAVE_SYS_PARAM_H
33
#include <sys/param.h>
35
#include <sys/types.h>
40
#include <X11/keysym.h>
41
#include <X11/cursorfont.h>
43
#include <X11/extensions/Xinerama.h>
45
/* temporary hack {{{ */
46
#include <WINGs/WINGsP.h>
52
/*###################################################################*/
54
/** Global Variables and Constants **/
59
static int help_heigth = 140;
60
static int text_width = 150, text_heigth = 26;
62
static char displayArgDefault[] = "";
63
static char *displayArg = displayArgDefault;
65
/*###################################################################*/
67
static int WmDefUser = False; /* default username */
69
static char *helpArg = NULL;
70
static char *HelpMsg = N_("no help available.");
72
/*###################################################################*/
74
typedef struct LoginPanel
79
WMFrame *logoF1, *logoF2;
82
WMLabel *welcomeMsg1, *welcomeMsg2;
83
WMTextField *entryText;
91
WMPopUpButton *exitBtn;
94
WMButton *startoverBtn;
105
static LoginPanel *panel = NULL;
107
/*###################################################################*/
109
static int LoginSwitch = False;
110
static char *LoginName = NULL;
111
static char *LoginPswd = NULL;
113
static int OptionCode = 0;
114
static char *ExitStr[] = { N_("Login"), N_("Reboot"), N_("Halt"),
115
#ifdef WITH_EXITLOGIN
120
static char *ExitFailStr[] = { N_("Login failed"), N_("Reboot failed"),
122
#ifdef WITH_EXITLOGIN
123
N_("ExitLogin failed"),
127
static int WmOptionCode = 0;
128
static char WmDefault[] = "wmaker:afterstep:xsession";
129
static char *WmArg = WmDefault;
130
static char **WmStr = NULL;
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;
140
static int xinerama_head = 0;
143
static WDMLoginConfig *cfg;
145
static int exit_request = 0;
147
char *ProgName = "Login";
150
read_help_file(int handle)
152
char *HelpText = NULL;
155
if(fstat(handle, &s) == 0)
157
HelpText = wmalloc(s.st_size + 1);
158
if(read(handle, HelpText, s.st_size) == -1)
160
WDMError("%s - read_help_file(): can't read %s\n",
165
HelpText[s.st_size] = '\0';
168
WDMError("%s - read_help_file(): can't stat %s\n",
178
char *HelpText = NULL;
179
char *defaultHelpText = NULL;
181
/* a good default value, even in case of errors */
182
defaultHelpText = wstrconcat("wdm --- " PACKAGE_VERSION "\n\n\n\n\n",
184
HelpText = defaultHelpText;
188
if((handle = open(helpArg, O_RDONLY)) == -1)
190
WDMError("%s - parse_helpArg(): can't open %s\n",
192
return defaultHelpText;
195
if((HelpText = read_help_file(handle)) != NULL)
196
wfree(defaultHelpText);
204
/*###################################################################*/
207
wAbort() /* for WINGs compatibility */
209
WDMPanic("%s - wAbort from WINGs\n", ProgName);
212
/*###################################################################*/
214
/*** pipe I/O routines ***/
216
/** The following code was adapted from out.c by Tom Rothamel */
218
/* This file is Copyright 1998 Tom Rothamel. It's under the Gnu Public *
219
* license, see the file COPYING for details. */
222
writeuc(int fd, unsigned char c)
224
write(fd, &c, sizeof(unsigned char));
228
writestring(int fd, char *string)
232
len = strlen(string);
236
writeuc(fd, (unsigned char) len);
237
write(fd, string, len);
241
/*** communicate authentication information ***/
244
OutputAuth(char *user, char *pswd)
246
writestring(wdm_fd, user ? user : "");
247
writestring(wdm_fd, pswd ? pswd : "");
251
if(WmOptionCode == 0)
252
writeuc(wdm_fd, 0); /* end of data */
256
writestring(wdm_fd, WmStr[WmOptionCode]);
257
writeuc(wdm_fd, 0); /* end of data */
262
writeuc(wdm_fd, OptionCode + 1);
263
writestring(wdm_fd, ExitStr[OptionCode]);
264
writeuc(wdm_fd, 0); /* end of data */
269
/*###################################################################*/
277
/* count number of items, skip empty items.
278
n = number of items - 1 */
280
if(*ptr++ == ':' && *ptr != ':' && *ptr)
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");
287
if(strcasecmp(WmArg, "none") != 0) /* we explicitly don't want any
298
while(*ptr != ':' && *ptr)
304
WmStr[i++] = N_("failsafe");
311
LoginArgs(int argc, char *argv[])
316
while((c = getopt(argc, argv, "asb:d:h:l:uw:c:x:f:")) != -1)
326
case 'd': /* display */
329
case 'h': /* helpfile */
335
case 'u': /* default user */
338
case 'w': /* wm list */
341
case 'b': /* background */
344
case 'c': /* configfile */
347
case 'f': /* filedescriptor for wdm comm.*/
348
wdm_fd = strtol(optarg, NULL, 0);
349
if(wdm_fd < 1) wdm_fd = 1;
352
case 'x': /* xinerama head */
353
xinerama_head = strtol(optarg, NULL, 0);
357
WDMError("bad option: %c\n", c);
363
/*###################################################################*/
365
/* write error message to the panel */
368
ClearMsgs(LoginPanel * panel)
370
WMSetFrameRelief(panel->msgF, WRFlat);
371
WMSetFrameTitle(panel->msgF, "");
372
WMSetLabelText(panel->msgL, "");
373
panel->msgFlag = False;
374
XFlush(WMScreenDisplay(panel->scr));
378
PrintErrMsg(LoginPanel * panel, char *msg)
381
struct timespec timeReq;
383
XSynchronize(WMScreenDisplay(panel->scr), True);
385
WMSetFrameRelief(panel->msgF, WRGroove);
386
WMSetFrameTitle(panel->msgF, _("ERROR"));
387
WMSetLabelText(panel->msgL, msg);
388
panel->msgFlag = True;
389
XFlush(WMScreenDisplay(panel->scr));
391
/* shake the panel like Login.app */
395
timeReq.tv_nsec = 15;
396
for(i = 0; i < 3; i++)
398
for(x = 2; x <= 30; x += 10)
400
WMMoveWidget(panel->win,
401
cfg->geometry.pos.x + x,
402
cfg->geometry.pos.y);
403
nanosleep(&timeReq, NULL);
405
for(x = 30; x >= -30; x -= 10)
407
WMMoveWidget(panel->win,
408
cfg->geometry.pos.x + x,
409
cfg->geometry.pos.y);
410
nanosleep(&timeReq, NULL);
412
for(x = -28; x <= 0; x += 10)
414
WMMoveWidget(panel->win,
415
cfg->geometry.pos.x + x,
416
cfg->geometry.pos.y);
417
nanosleep(&timeReq, NULL);
419
XFlush(WMScreenDisplay(panel->scr));
422
XSynchronize(WMScreenDisplay(panel->scr), False);
425
/* write info message to panel */
428
PrintInfoMsg(LoginPanel * panel, char *msg)
430
XSynchronize(WMScreenDisplay(panel->scr), True);
432
WMSetLabelText(panel->msgL, msg);
433
XFlush(WMScreenDisplay(panel->scr));
434
panel->msgFlag = True;
435
XSynchronize(WMScreenDisplay(panel->scr), False);
438
/*###################################################################*/
441
init_pwdfield(char *pwd)
443
WMSetTextFieldText(panel->entryText, pwd);
444
WMSetTextFieldSecure(panel->entryText, True);
445
WMSetLabelText(panel->entryLabel, _("Password:"));
449
init_namefield(char *name)
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);
459
InitializeLoginInput(LoginPanel * panel)
473
PerformLogin(LoginPanel * panel, int canexit)
475
if(LoginSwitch == False)
479
LoginName = WMGetTextFieldText(panel->entryText);
481
if((LoginName[0] == '\0') && (WmDefUser == False))
483
InitializeLoginInput(panel);
484
PrintErrMsg(panel, _("invalid name"));
490
init_pwdfield(LoginPswd);
496
LoginPswd = WMGetTextFieldText(panel->entryText);
500
init_namefield(LoginName);
506
PrintInfoMsg(panel, _("validating"));
508
PrintInfoMsg(panel, _("exiting"));
510
OutputAuth(LoginName, LoginPswd);
513
/*###################################################################*/
519
goPressed(WMWidget * self, LoginPanel * panel)
523
if(LoginSwitch == False)
525
PerformLogin(panel, True);
526
if(LoginSwitch == False)
529
PerformLogin(panel, True);
532
if(LoginSwitch == True)
536
LoginPswd = WMGetTextFieldText(panel->entryText);
537
WMSetTextFieldText(panel->entryText, "");
539
PrintInfoMsg(panel, _("exiting"));
540
OutputAuth(LoginName, LoginPswd);
544
startoverPressed(WMWidget * self, LoginPanel * panel)
547
InitializeLoginInput(panel);
551
helpPressed(WMWidget * self, LoginPanel * panel)
553
static Bool helpshown = False;
557
WMSetButtonText(panel->helpBtn, _("Close Help"));
558
WMResizeWidget(panel->win, WMWidgetWidth(panel->win),
559
WMWidgetHeight(panel->win) + help_heigth);
564
WMSetButtonText(panel->helpBtn, _("Help"));
565
WMResizeWidget(panel->win, WMWidgetWidth(panel->win),
566
WMWidgetHeight(panel->win) - help_heigth);
571
changeWm(WMWidget * self, LoginPanel * panel)
573
WmOptionCode = WMGetPopUpButtonSelectedItem(self);
574
WMSetFocusToWidget(panel->entryText);
578
changeOption(WMPopUpButton * self, LoginPanel * panel)
582
item = WMGetPopUpButtonSelectedItem(self);
584
WMSetFocusToWidget(panel->entryText);
588
handleKeyPress(XEvent * event, void *clientData)
590
LoginPanel *panel = (LoginPanel *) clientData;
596
if(event->xkey.keycode == panel->retkey)
598
PerformLogin(panel, True);
600
else if(event->xkey.keycode == panel->tabkey)
602
PerformLogin(panel, False);
606
/*###################################################################*/
608
/* create and destroy our panel */
611
CreateLogo(LoginPanel * panel)
613
RImage *image1, *image2;
617
unsigned w = 200, h = 130;
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);
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);
632
panel->logoL = WMCreateLabel(panel->logoF2);
633
WMMoveWidget(panel->logoL, 2, 2);
634
WMResizeWidget(panel->logoL, 200, 130);
635
WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
637
context = WMScreenRContext(panel->scr);
641
image1 = RLoadImage(context, logoArg, 0);
645
RColor first, second;
652
image1 = RRenderGradient(200, 300, &first, &second, RDiagonalGradient);
658
WDMDebug("width=%i,heigth=%i\n", image1->width, image1->height);
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);
666
WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
668
if(image1->height > 130)
672
ratio = (float) 130. / (float) h;
673
w = (int) ((float) w * ratio);
678
WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
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))
687
/* last check in case the above logic is faulty */
693
WDMDebug("new: ratio=%.5f,width=%i,heigth=%i\n", ratio, w, h);
696
image2 = RSmoothScaleImage(image1, w, h);
698
image2 = RScaleImage(image1, w, h);
700
RReleaseImage(image1);
706
RCombineImageWithColor(image2, &gray);
707
pixmap = WMCreatePixmapFromRImage(panel->scr, image2, 0);
708
RReleaseImage(image2);
712
WDMError("unable to load pixmap\n");
715
WMSetLabelImage(panel->logoL, pixmap);
716
WMReleasePixmap(pixmap);
721
CreateAuthFrame(LoginPanel * panel)
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);
734
gethostname(str, 127);
737
panel->welcomeMsg1 = WMCreateLabel(panel->authF);
738
WMResizeWidget(panel->welcomeMsg1, 255, 26);
739
WMSetLabelText(panel->welcomeMsg1, _("Welcome to"));
740
WMMoveWidget(panel->welcomeMsg1, 11, y);
742
WMSetLabelTextAlignment(panel->welcomeMsg1, WACenter);
743
font = WMBoldSystemFontOfSize(panel->scr, 18);
746
WMSetLabelFont(panel->welcomeMsg1, font);
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);
764
font = WMBoldSystemFontOfSize(panel->scr, y);
767
WMSetLabelFont(panel->welcomeMsg2, font);
773
panel->entryLabel = WMCreateLabel(panel->authF);
774
WMMoveWidget(panel->entryLabel, 10, y);
775
WMResizeWidget(panel->entryLabel, 100, 26);
776
font = WMBoldSystemFontOfSize(panel->scr, 14);
779
WMSetLabelFont(panel->entryLabel, font);
782
WMSetLabelText(panel->entryLabel, _("Login name:"));
783
WMSetLabelTextAlignment(panel->entryLabel, WARight);
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);
793
CreateMsgsFrames(LoginPanel * panel)
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, "");
804
panel->msgL = WMCreateLabel(panel->msgF);
805
WMResizeWidget(panel->msgL, 260, 26);
806
WMMoveWidget(panel->msgL, 5, 2);
807
font = WMBoldSystemFontOfSize(panel->scr, 14);
810
WMSetLabelFont(panel->msgL, font);
813
WMSetLabelText(panel->msgL, "");
814
WMSetLabelTextAlignment(panel->msgL, WARight);
819
CreatePopups(LoginPanel * panel)
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);
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);
835
while(WmStr[i] != NULL)
837
WMAddPopUpButtonItem(panel->wmBtn, _(WmStr[i]));
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);
848
panel->exitBtn = WMCreatePopUpButton(panel->exitF);
849
WMMoveWidget(panel->exitBtn, 4, 15);
850
WMResizeWidget(panel->exitBtn, 90, 25);
851
WMSetPopUpButtonAction(panel->exitBtn, (WMAction *) changeOption,
854
while(ExitStr[i] != NULL)
856
WMAddPopUpButtonItem(panel->exitBtn, _(ExitStr[i]));
862
CreateButtons(LoginPanel * panel)
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);
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);
880
panel->startoverBtn = WMCreateCommandButton(panel->cmdF);
881
WMSetButtonAction(panel->startoverBtn, (WMAction *) startoverPressed,
883
WMMoveWidget(panel->startoverBtn, i, 8);
884
WMSetButtonText(panel->startoverBtn, _("Start Over"));
885
WMResizeWidget(panel->startoverBtn, 80, 25);
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);
896
CreateHelpFrames(LoginPanel * panel)
899
char *HelpText = NULL;
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);
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);
915
HelpText = parse_helpArg();
917
panel->helpTextF = WMCreateFrame(panel->helpF);
918
WMSetFrameRelief(panel->helpTextF, WRFlat);
919
panel->helpTextL = WMCreateLabel(panel->helpTextF);
920
WMSetLabelTextAlignment(panel->helpTextL, WALeft);
922
height = W_GetTextHeight(WMDefaultSystemFont(panel->scr),
923
HelpText, (WMWidgetWidth(panel->win) - 60), True) + 10;
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);
931
WMSetLabelText(panel->helpTextL, HelpText);
932
WMSetLabelWraps(panel->helpTextL, True);
938
CreateLoginPanel(WMScreen *scr, WDMLoginConfig *cfg)
942
panel = malloc(sizeof(LoginPanel));
945
memset(panel, 0, sizeof(LoginPanel));
948
/* basic window and frames */
950
panel->win = WMCreateWindow(scr, ProgName);
951
WMResizeWidget(panel->win,
952
cfg->geometry.size.width, cfg->geometry.size.height);
954
panel->winF1 = WMCreateFrame(panel->win);
955
WMResizeWidget(panel->winF1,
956
cfg->geometry.size.width, cfg->geometry.size.height);
957
WMSetFrameRelief(panel->winF1, WRRaised);
959
CreateAuthFrame(panel);
965
CreateButtons(panel);
967
CreateMsgsFrames(panel);
969
CreateHelpFrames(panel);
971
WMRealizeWidget(panel->win);
972
WMMapSubwidgets(panel->win);
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));
989
WMSetPopUpButtonSelectedItem(panel->wmBtn, 0);
990
WMSetPopUpButtonSelectedItem(panel->exitBtn, 0);
992
panel->msgFlag = False;
998
DestroyLoginPanel(LoginPanel * panel)
1001
struct timespec timeReq;
1003
/* roll up the window before destroying it */
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)
1013
WMResizeWidget(panel->win, width, height);
1014
nanosleep(&timeReq, NULL);
1016
XSynchronize(WMScreenDisplay(panel->scr), False);
1018
WMUnmapWidget(panel->win);
1019
WMDestroyWidget(panel->win);
1023
/*###################################################################*/
1025
/** set the background **/
1034
tmp = strchr(bgArg, ':');
1039
while(*bgOption == ' ')
1041
if(*bgOption == '\0')
1046
*tmp = tolower(*tmp);
1049
if(strcmp(bgArg, "pixmap") == 0)
1051
if(strcmp(bgArg, "solid") == 0)
1053
if(strcmp(bgArg, "hgradient") == 0)
1055
if(strcmp(bgArg, "vgradient") == 0)
1057
if(strcmp(bgArg, "dgradient") == 0)
1063
loadBGpixmap(RContext * rcontext)
1065
RImage *image, *tmp;
1067
image = RLoadImage(rcontext, bgOption, 0);
1070
WDMError("%s could not load bg image %s\n",
1071
ProgName, bgOption);
1074
tmp = RScaleImage(image, screen.size.width, screen.size.height);
1077
WDMError("%s could not resize bg image %s\n",
1078
ProgName, bgOption);
1079
RReleaseImage(image);
1082
RReleaseImage(image);
1089
RColor **colors = NULL;
1092
colors = malloc(sizeof(RColor *) * (num + 1));
1093
for(i = 0; i < num; i++)
1095
colors[i] = malloc(sizeof(RColor));
1102
freemem(int num, RColor ** colors)
1106
for(i = 0; i < num; i++)
1114
createBGcolor(WMScreen * scr, RContext * rcontext, char *str, int style)
1117
RColor **colors = NULL;
1121
char *tmp, *colorstr;
1127
tmp = strchr(colorstr, ',');
1129
colorstr = str + strlen(str);
1135
colors = allocmem(num_colors);
1137
for(i = 0; i < num_colors; i++)
1140
tmp = strchr(tmp, ',');
1147
tmp = colorstr + strlen(colorstr);
1149
(WMScreenDisplay(scr), rcontext->cmap, colorstr, &color))
1151
WDMError("could not parse color \"%s\"\n",
1153
freemem(num_colors, colors);
1156
colors[i]->red = color.red >> 8;
1157
colors[i]->green = color.green >> 8;
1158
colors[i]->blue = color.blue >> 8;
1160
image = RRenderMultiGradient(screen.size.width, screen.size.height,
1162
freemem(num_colors, colors);
1167
setBG(WMScreen * scr)
1170
int cpc = 4, render_mode = RBestMatchRendering, default_depth = 8;
1171
RContextAttributes rattr;
1177
/* if not specified or none, then skip setting background */
1178
/* user can still set background via other means */
1181
if(strcasecmp(bgArg, "none") == 0)
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)
1196
WDMError("%s could not initialize "
1197
"graphics library context: %s\n",
1198
ProgName, RMessageForError(RErrorCode));
1202
defcolor.pixel = 0L; /* default=black */
1207
image = loadBGpixmap(rcontext);
1210
image = createBGcolor(scr, rcontext, bgOption, RGRD_HORIZONTAL);
1213
image = createBGcolor(scr, rcontext, bgOption, RGRD_HORIZONTAL);
1216
image = createBGcolor(scr, rcontext, bgOption, RGRD_VERTICAL);
1219
image = createBGcolor(scr, rcontext, bgOption, RGRD_DIAGONAL);
1227
XSetWindowBackground(WMScreenDisplay(scr), root_window, 0L);
1228
XClearWindow(WMScreenDisplay(scr), root_window);
1229
XFlush(WMScreenDisplay(scr));
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));
1239
/*###################################################################*/
1241
/* signal processing */
1244
SignalUsr1(int ignored) /* oops, an error */
1246
InitializeLoginInput(panel);
1247
PrintErrMsg(panel, _(ExitFailStr[OptionCode]));
1248
signal(SIGUSR1, SignalUsr1);
1252
SignalTerm(int ignored) /* all done */
1254
exit_request = 1; /* corrects some hanging problems, thanks to A. Kabaev */
1257
/*###################################################################*/
1262
main(int argc, char **argv)
1267
#ifdef HAVE_XINERAMA
1268
XineramaScreenInfo *xine;
1273
setlocale(LC_ALL, "");
1276
if(getenv("NLSPATH"))
1277
bindtextdomain("wdm", getenv("NLSPATH"));
1279
bindtextdomain("wdm", NLSDIR);
1280
#if WINGS_H_VERSION >= 20040406
1281
bind_textdomain_codeset("wdm", "UTF-8");
1287
LoginArgs(argc, argv); /* process our args */
1289
cfg = LoadConfiguration(configFile); /* load configs */
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);
1299
SetupWm(); /* and init the startup list */
1301
WMInitializeApplication(ProgName, &argc, argv);
1302
scr = WMOpenScreen(displayArg);
1305
WDMPanic("could not initialize Screen\n");
1309
#if WINGS_H_VERSION < 20040406
1311
scr->useMultiByte = True;
1317
scr->antialiasedText = True;
1318
scr->normalFont = WMSystemFontOfSize(scr,
1319
WINGsConfiguration.defaultFontSize);
1321
scr->boldFont = WMBoldSystemFontOfSize(scr,
1322
WINGsConfiguration.defaultFontSize);
1325
scr->boldFont = scr->normalFont;
1327
if(!scr->normalFont)
1329
WDMError("could not load any fonts.");
1339
screen.size.width = WMScreenWidth(scr);
1340
screen.size.height = WMScreenHeight(scr);
1341
#ifdef HAVE_XINERAMA
1342
if(XineramaIsActive(WMScreenDisplay(scr)))
1344
xine = XineramaQueryScreens(WMScreenDisplay(scr), &xine_count);
1348
if(xinerama_head < xine_count)
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;
1359
if(cfg->geometry.pos.x == INT_MIN || cfg->geometry.pos.y == INT_MIN)
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;
1367
XSynchronize(WMScreenDisplay(scr), False);
1369
/* use of scr->rootWin is temporary hack */
1370
XWarpPointer(WMScreenDisplay(scr), None,
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),
1378
XCreateFontCursor(WMScreenDisplay(scr),
1379
XC_top_left_arrow));
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);
1399
WMCreateEventHandler(WMWidgetView(panel->entryText), KeyPressMask,
1400
handleKeyPress, panel);
1403
signal(SIGUSR1, SignalUsr1);
1404
signal(SIGTERM, SignalTerm);
1405
signal(SIGINT, SignalTerm);
1406
signal(SIGPIPE, SIG_DFL);
1408
while(!exit_request)
1411
WMNextEvent(WMScreenDisplay(scr), &event);
1412
WMHandleEvent(&event);
1414
DestroyLoginPanel(panel);