File: xpmroot.c

package info (click to toggle)
fvwm1 1.24r-56
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 2,060 kB
  • ctags: 2,032
  • sloc: ansic: 23,586; sh: 108; makefile: 91
file content (128 lines) | stat: -rw-r--r-- 3,238 bytes parent folder | download | duplicates (8)
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
/****************************************************************************
 * This is an all new program to set the root window to an Xpm pixmap.
 * Copyright 1993, Rob Nation
 * You may use this file for anything you want, as long as the copyright
 * is kept intact. No guarantees of any sort are made in any way regarding
 * this program or anything related to it.
 ****************************************************************************/

#include "../configure.h"

#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/xpm.h>
#include "../version.h"
#include "../libs/fvwmlib.h"     
int save_colors = 0;
Display *dpy;
int screen;
Window root;
char *display_name = NULL;
void SetRootWindow(char *tline);
Pixmap rootXpm;

int main(int argc, char **argv)
{
  Atom prop, type;
  int format;
  unsigned long length, after;
  unsigned char *data;

  if(argc != 2)
    {
      fprintf(stderr,"Xpmroot Version %s\n",VERSION);
      fprintf(stderr,"Usage: xpmroot xpmfile\n");
      fprintf(stderr,"Try Again\n");
      exit(1);
    }
  dpy = XOpenDisplay(display_name);
  if (!dpy) 
    {
      fprintf(stderr, "Xpmroot:  unable to open display '%s'\n",
	      XDisplayName (display_name));
      exit (2);
    }
  screen = DefaultScreen(dpy);
  root = RootWindow(dpy, screen);
  
  SetRootWindow(argv[1]);

  prop = XInternAtom(dpy, "_XSETROOT_ID", False);
  
  (void)XGetWindowProperty(dpy, root, prop, 0L, 1L, True, AnyPropertyType,
			   &type, &format, &length, &after, &data);
  if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
    XKillClient(dpy, *((Pixmap *)data));

  XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace,
		  (unsigned char *) &rootXpm, 1);
  XSetCloseDownMode(dpy, RetainPermanent);
  XCloseDisplay(dpy);
  return 0;
}


void SetRootWindow(char *tline)
{
  XWindowAttributes root_attr;
  XpmAttributes xpm_attributes;
  Pixmap shapeMask;
  int val;

  XGetWindowAttributes(dpy,root,&root_attr);
  xpm_attributes.colormap = root_attr.colormap;
  xpm_attributes.valuemask = XpmSize | XpmReturnPixels|XpmColormap;
  if((val = XpmReadFileToPixmap(dpy,root, tline,
			 &rootXpm, &shapeMask, 
			 &xpm_attributes))!= XpmSuccess) 
    {
      if(val == XpmOpenFailed)
	fprintf(stderr, "Couldn't open pixmap file\n");
      else if(val == XpmColorFailed)
	fprintf(stderr, "Couldn't allocated required colors\n");
      else if(val == XpmFileInvalid)
	fprintf(stderr, "Invalid Format for an Xpm File\n");
      else if(val == XpmColorError)
	fprintf(stderr, "Invalid Color specified in Xpm FIle\n");
      else if(val == XpmNoMemory)
	fprintf(stderr, "Insufficient Memory\n");
      exit(1);
    }

  XSetWindowBackgroundPixmap(dpy, root, rootXpm);
  save_colors = 1;
  XClearWindow(dpy,root);

}


#ifdef NEEDS_STRCASECMP
int strcasecmp(char *s1,char *s2)
{
  int c1,c2;
  int n,n2;

  n=strlen(s1);
  n2=strlen(s2);
  if(n!=n2)
    return 1;

  for (;;)
    {
      c1 = *s1; 
      c2 = *s2;
      if (!c1 || !c2) 
	return(c1 - c2);
      if (isupper(c1)) 
	c1 = 'a' - 1 + (c1 & 31);
      if (isupper(c2)) 
	c2 = 'a' - 1 + (c2 & 31);
      if (c1 != c2) 
	return(c1 - c2);
      n--,s1++,s2++;
    }
}
#endif