File: Basewindow.cc

package info (click to toggle)
bbtime 0.1.5-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 456 kB
  • ctags: 510
  • sloc: cpp: 4,175; sh: 327; makefile: 88
file content (164 lines) | stat: -rw-r--r-- 4,563 bytes parent folder | download | duplicates (6)
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
//  Basewindow.cc for bbtools.
//
//  Copyright (c) 1998-1999 by John Kennis, jkennis@chello.nl
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// (See the included file COPYING / GPL-2.0)
//
#include "Basewindow.hh"
#include "resource.hh"

Basewindow::Basewindow(int argc,char **argv)
{
	display_name=NULL;
	config_filename=NULL;
	position=NULL;
	withdrawn=False;
	shape=False;	
	server_grabs=0;

	ParseOptions(argc,argv);

	dpy=NULL;
	dpy=XOpenDisplay(display_name);
	if (dpy==NULL)
	{
		fprintf(stderr,"Error can't open display %s\n",display_name);
		exit(1);
	}

	screen=DefaultScreen(dpy);
	v=DefaultVisual(dpy,screen);
	root=RootWindow(dpy,screen);
	depth=DefaultDepth(dpy,screen);
	display_height=DisplayHeight(dpy,screen);
	display_width=DisplayWidth(dpy,screen);

	xres = WidthOfScreen(ScreenOfDisplay(dpy, screen));
	yres = HeightOfScreen(ScreenOfDisplay(dpy, screen));	

	MakeCursor();

}

Basewindow::~Basewindow()
{
}

void Basewindow::MakeCursor(void)
{
	cursor = XCreateFontCursor(dpy, XC_left_ptr);
	XDefineCursor(dpy, root, cursor);
}


void Basewindow::setupImageControl()
{
	image_control = new BImageControl(this);
	image_control->installRootColormap();
}


void Basewindow::grab(void)
{
	if (! server_grabs++);
	   XGrabServer(dpy);

	XSync(dpy, False);
}

void Basewindow::ungrab(void)
{
	if (! --server_grabs);
  	XUngrabServer(dpy);

	if (server_grabs < 0) server_grabs = 0;
}

void Basewindow::ParseOptions(int argc,char **argv)
{
	int i;

	for(i=1;i<argc;i++)
	{
		if ((!strcmp(argv[i],"-display"))|(!strcmp(argv[i],"-d")))
		{
			if(++i==argc)  { Usage(); exit(2); };
			display_name=argv[i];
		}
 		else if ((!strcmp(argv[i],"-bbconfig"))|(!strcmp(argv[i],"-bb")))
		{
			if(++i==argc)  { Usage(); exit(2); };
      if (config_filename||default_config) { Usage(); exit(2); };
      bbconfig_filename=argv[i];
		}
 		else if ((!strcmp(argv[i],"-config"))|(!strcmp(argv[i],"-c")))

		{
			if(++i==argc)  { Usage(); exit(2); };
      if (bbconfig_filename||default_config) { Usage(); exit(2); };
			config_filename=argv[i];
		}
 		else if ((!strcmp(argv[i],"-default"))|(!strcmp(argv[i],"-d")))
		{
      if (bbconfig_filename||config_filename) { Usage(); exit(2); };
      { Usage(); exit(2); };
      default_config=True;
    }
    		else if ( (!strcmp(argv[i],"-v")) || (!strcmp(argv[i],"-version")))
		{
			fprintf(stderr," %s version %s\n",BBTOOL,BBTOOL_VERSION);
			exit(2);
		}
    		else if ( (!strcmp(argv[i],"-h")) || (!strcmp(argv[i],"-help")))
		{
			Usage();
			exit(2);
		}
    		else if ((!strcmp(argv[i],"-position")) || (!strcmp(argv[i],"-p")))
		{
			if(++i==argc)  { Usage(); exit(2); };
			position=argv[i];
		}
			else if ((!strcmp(argv[i],"-withdrawn")) || (!strcmp(argv[i],"-w")))
		{
		 	withdrawn=True;
		}	
			else if ((!strcmp(argv[i],"-shape")) || (!strcmp(argv[i],"-s")))
		{
		 	shape=True;
		}			
	}
}

void Basewindow::Usage()
{
	fprintf(stderr,"%s version %s \n\n",BBTOOL,BBTOOL_VERSION);
	fprintf(stderr,"%s [-display <display name>] [-config <filename>]\n",BBTOOL);
	fprintf(stderr,"       [-spooldir] [-version] [-help]\n");
	fprintf(stderr,"       [[-position] | [-pos]] <position>\n\n");
	fprintf(stderr,"-d[isplay] <display name>   X server to connect to\n");
	fprintf(stderr,"-c[onfig] <filename>        Alternate config file\n");
	fprintf(stderr,"-bb[config] <filename>      Alternate Blackbox config file\n");
	fprintf(stderr,"-def[ault]                  Fall back on default configuration\n");
	fprintf(stderr,"-v[ersion]                  Display version number\n");
	fprintf(stderr,"-h[elp]                     Display this help\n");
	fprintf(stderr,"-p[osition] <position>      Set position of window\n");
	fprintf(stderr,"            <position> = [+]|[-]x[+]|[-]y\n");
	fprintf(stderr,"-w[withdrawn]               Place bbtool in the Slit\n");
	fprintf(stderr,"-s[hape]                    Don't display groundplate\n\n");	
}