223
222
/* Functions *****************************************************************/
225
224
/* Defer signals to protect the server grab ================================ */
226
void xsublim_Sig_Catch(int sig_Number)
225
static void xsublim_Sig_Catch(int sig_Number)
228
227
/* BSD needs this reset each time, and it shouldn't hurt anything
422
disp_Display = XtDisplay(app_App);
423
db = XtDatabase(disp_Display);
424
XtGetApplicationNameAndClass(disp_Display,&progname,&progclass);
424
dpy = XtDisplay(app_App);
425
XtGetApplicationNameAndClass(dpy,&progname,&progclass);
425
426
win_Root = RootWindowOfScreen(XtScreen(app_App));
426
427
XtDestroyWidget(app_App);
428
429
/* Get the arguments */
429
arg_FlagCenter = get_boolean_resource(XSUBLIM_ARG_CENTER,"Boolean");
430
arg_FlagOutline = get_boolean_resource(XSUBLIM_ARG_OUTLINE,"Boolean");
431
arg_FlagScreensaver = get_boolean_resource(XSUBLIM_ARG_SCREENSAVER,
430
arg_FlagCenter = get_boolean_resource(dpy, XSUBLIM_ARG_CENTER,"Boolean");
431
arg_FlagOutline = get_boolean_resource(dpy, XSUBLIM_ARG_OUTLINE,"Boolean");
432
arg_FlagScreensaver = get_boolean_resource(dpy, XSUBLIM_ARG_SCREENSAVER,
433
arg_FlagRandom = get_boolean_resource(XSUBLIM_ARG_RANDOM,"Boolean");
434
arg_DelayShow = get_integer_resource(XSUBLIM_ARG_DELAYSHOW,"Integer");
435
arg_DelayWord = get_integer_resource(XSUBLIM_ARG_DELAYWORD,"Integer");
436
arg_DelayPhraseMin = get_integer_resource(XSUBLIM_ARG_DELAYPHRASEMIN,
434
arg_FlagRandom = get_boolean_resource(dpy, XSUBLIM_ARG_RANDOM,"Boolean");
435
arg_DelayShow = get_integer_resource(dpy, XSUBLIM_ARG_DELAYSHOW,"Integer");
436
arg_DelayWord = get_integer_resource(dpy, XSUBLIM_ARG_DELAYWORD,"Integer");
437
arg_DelayPhraseMin = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMIN,
438
arg_DelayPhraseMax = get_integer_resource(XSUBLIM_ARG_DELAYPHRASEMAX,
439
arg_DelayPhraseMax = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMAX,
440
441
if (arg_DelayPhraseMax < arg_DelayPhraseMin)
558
559
/* Load the font */
559
font_Font = XLoadQueryFont(disp_Display,
560
get_string_resource(XSUBLIM_ARG_FONT,"Font"));
560
font_Font = XLoadQueryFont(dpy,
561
get_string_resource(dpy, XSUBLIM_ARG_FONT,"Font"));
562
563
while ((font_Font == NULL) && (font_List[font_Index] != NULL))
564
font_Font = XLoadQueryFont(disp_Display,font_List[font_Index]);
565
font_Font = XLoadQueryFont(dpy,font_List[font_Index]);
567
568
if (font_Font == NULL)
573
574
/* Create the GCs */
574
XGetWindowAttributes(disp_Display,win_Root,&attr_Win);
575
XGetWindowAttributes(dpy,win_Root,&attr_Win);
575
576
gc_ValFore.font = font_Font->fid;
576
gc_ValFore.foreground = get_pixel_resource("foreground","Foreground",
577
disp_Display,attr_Win.colormap);
578
gc_ValFore.background = get_pixel_resource("background","Background",
579
disp_Display,attr_Win.colormap);
577
gc_ValFore.foreground = get_pixel_resource(dpy,
579
"foreground","Foreground");
580
gc_ValFore.background = get_pixel_resource(dpy,
582
"background","Background");
580
583
gc_ValFore.subwindow_mode = IncludeInferiors;
581
gc_GcFore = XCreateGC(disp_Display,win_Root,
584
gc_GcFore = XCreateGC(dpy,win_Root,
582
585
(GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValFore);
583
586
gc_ValBack.font = font_Font->fid;
584
gc_ValBack.foreground = get_pixel_resource("background","Background",
585
disp_Display,attr_Win.colormap);
586
gc_ValBack.background = get_pixel_resource("foreground","Foreground",
587
disp_Display,attr_Win.colormap);
587
gc_ValBack.foreground = get_pixel_resource(dpy,
589
"background","Background");
590
gc_ValBack.background = get_pixel_resource(dpy,
592
"foreground","Foreground");
588
593
gc_ValBack.subwindow_mode = IncludeInferiors;
589
gc_GcBack = XCreateGC(disp_Display,win_Root,
594
gc_GcBack = XCreateGC(dpy,win_Root,
590
595
(GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValBack);
592
597
/* Loop ------------------------------------------------------------ */
640
645
/* Once-per-word stuff ----------------------------- */
642
647
/* Find the text's position */
643
XGetWindowAttributes(disp_Display,win_Root,&attr_Win);
648
XGetWindowAttributes(dpy,win_Root,&attr_Win);
644
649
text_Length = strlen(text_Word);
645
650
text_Width = XTextWidth(font_Font,text_Word,
646
651
text_Length)+XSUBLIM_TEXT_OUTLINE*2;
687
692
/* Grab the server -- we can't let anybody draw over
689
XSync(disp_Display,FALSE);
690
XGrabServer(disp_Display);
691
XSync(disp_Display,FALSE);
693
698
/* Set up an error handler that ignores BadMatches --
694
699
since the screensaver can take its window away at
698
703
XSetErrorHandler(xsublim_Sh_Handler);
700
705
/* Save the current background */
701
image_Image = XGetImage(disp_Display,win_Root,image_X,
706
image_Image = XGetImage(dpy,win_Root,image_X,
702
707
image_Y,image_Width,image_Height,~0L,ZPixmap);
704
709
/* If we've successfully saved the background... */
747
752
if (Xsublim_Sh_Status == 0)
750
XSync(disp_Display,FALSE);
751
756
if (Xsublim_Sig_Last == -1)
753
758
usleep(arg_DelayShow);
756
761
/* Restore the background */
757
XPutImage(disp_Display,win_Root,
762
XPutImage(dpy,win_Root,
758
763
gc_GcFore,image_Image,0,0,image_X,
759
764
image_Y,image_Width,image_Height);
766
771
/* Restore the error handler, ungrab the server */
767
XSync(disp_Display,FALSE);
768
773
XSetErrorHandler(Xsublim_Sh_Handler);
769
XUngrabServer(disp_Display);
770
XSync(disp_Display,FALSE);
772
777
/* Pause between words */
773
778
if (Xsublim_Sig_Last == -1)