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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
/* $Id: wmhtest.c,v 1.14 2005/09/05 10:45:48 pekberg Exp $
******************************************************************************
Test program for the "wmh" i.e. WindowManagerHints extension.
Copyright (C) 1999 Andreas Beck - becka@ggi-project.org
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include <ggi/gg.h>
#include <ggi/ggi.h>
#include <ggi/ggi_ext.h>
#include <ggi/wmh.h>
static int small_window = 0;
static int ggi_resize(ggi_visual_t vis, ggi_mode *mode)
{
ggi_color col;
int x,y;
fprintf(stderr,"Want resize to %dx%d\n",mode->visible.x,mode->visible.y);
mode->virt.x=mode->visible.x;
mode->virt.y=mode->visible.y;
ggiCheckMode(vis,mode);
ggiSetMode(vis,mode);
col.r = 0xffff;
col.g = 0xffff;
col.b = 0xffff;
ggiSetGCForeground(vis, ggiMapColor(vis, &col));
if(small_window)
ggiWmhAllowResize(vis,300,300,600,600,10,10);
else
ggiWmhAllowResize(vis,1,1,2000,2000,1,1);
for(y=0; y < mode->visible.y; y += 10) {
ggiDrawLine(vis,0,y,mode->visible.x-1,mode->visible.y-1-y);
} /* for */
for(x=0; x < mode->visible.x; x += 10) {
ggiDrawLine(vis,x,mode->visible.y-1,mode->visible.x-1-x,0);
} /* for */
ggiFlush(vis);
fprintf(stderr,"Want resize to %dx%d\n",mode->visible.x,mode->visible.y);
return 0;
} /* ggi_resize */
static int ggi_waitevent(ggi_visual_t vis)
{
struct timeval tv={0,0};
ggi_event ev, reqev;
int reqswitch = 0;
int n;
again:
reqswitch = 0;
ggiEventPoll(vis, emAll, &tv);
n = ggiEventsQueued(vis, emAll);
while( n-- ) {
ggiEventRead(vis, &ev, emAll);
fprintf(stderr,"Got in poll: %d\n",ev.any.type);
switch(ev.any.type) {
case evCommand:
if (ev.cmd.code==GGICMD_REQUEST_SWITCH) {
reqev = ev;
reqswitch = 1;
}
break;
case evKeyPress:
return 1;
} /* switch */
} /* while */
if (reqswitch) {
ggi_cmddata_switchrequest *req;
req = (ggi_cmddata_switchrequest *)&reqev.cmd.data;
ggi_resize(vis,&(req->mode));
goto again;
}
return 0;
} /* ggi_waitevent */
int main(void)
{
ggi_visual_t vis;
ggi_color col;
ggi_mode mode;
int temp, inc, width, height;
/* Initialize LibGGI */
if (ggiInit() != 0) {
fprintf(stderr, "Unable to initialize LibGGI\n");
exit(1);
} /* if */
/* Initialize WMH extension */
if (ggiWmhInit() != 0) {
ggiPanic("Unable to initialize LibGGIWMH extension\n");
} /* if */
/* Open the default visual */
if ((vis = ggiOpen(NULL)) == NULL) {
ggiPanic("Unable to open default visual\n");
} /* if */
/* Turn on asynchronous mode (which should always be used) */
ggiSetFlags(vis, GGIFLAG_ASYNC);
/* Set the default mode */
if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO) < 0) {
ggiPanic("Unable to set default mode\n");
} /* if */
/* Attach the WMH extension to the visual */
if (ggiWmhAttach(vis) < 0) {
ggiPanic("Unable to attach WMH extension to visual\n");
} /* if */
/* Set foreground color to white */
col.r = 0xffff;
col.g = 0xffff;
col.b = 0xffff;
ggiSetGCForeground(vis, ggiMapColor(vis, &col));
/* Check what mode we actually got */
ggiGetMode(vis, &mode);
width = mode.visible.x;
height = mode.visible.y;
/* Draw a bunch of lines... */
inc = height/66;
for (temp = 0; temp <= (height-inc); temp += inc) {
ggiDrawLine(vis, 0, temp, width-1, height-temp);
} /* for */
/* ...and flush the screen */
ggiFlush(vis);
/* Now test the window stuff */
ggiWmhSetTitle(vis,"This is LibGGIWMH resizing !");
ggiWmhSetIconTitle(vis,"WMH Icon Title");
ggiWmhAllowResize(vis,1,1,2000,2000,1,1);
for (temp = 10; temp < height; temp+=(height-10)/30) {
ggiWmhResize(vis, temp, temp);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(100000);
} /* for */
ggiWmhSetTitle(vis,"This is LibGGIWMH moving !");
for (temp = 0; temp < height/3; temp+=(height/3)/30) {
ggiWmhMove(vis, temp, temp);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(100000);
} /* for */
ggiWmhMove(vis, 40,40);
ggiWmhSetTitle(vis,"This is LibGGIWMH at the bottom !");
ggiWmhZOrder(vis,GGI_WMH_ZO_BOTTOM);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH at the top !");
ggiWmhZOrder(vis,GGI_WMH_ZO_TOP);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH iconified !");
ggiWmhIconify(vis,GGI_WMH_MAPSTATE_ICON);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH big again !");
ggiWmhIconify(vis,GGI_WMH_MAPSTATE_NORMAL);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH withdrawn !");
ggiWmhIconify(vis,GGI_WMH_MAPSTATE_WITHDRAWN);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH big again !");
ggiWmhIconify(vis,GGI_WMH_MAPSTATE_NORMAL);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(2000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH 100x10 % !");
ggiWmhMaximize(vis,100,10);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(1000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH 10x100 % !");
ggiWmhMaximize(vis,10,100);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(1000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH 100x100 % !");
ggiWmhMaximize(vis,100,100);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(1000000);
ggiWmhSetTitle(vis,"This is LibGGIWMH at the top !");
ggiWmhZOrder(vis,GGI_WMH_ZO_TOP);
ggiFlush(vis);
if (ggi_waitevent(vis)) goto cleanup;
ggUSleep(1000000);
ggiWmhSetTitle(vis,"You may now manually resize between 300 and 600 pixels !");
small_window = 1;
ggiWmhAllowResize(vis,300,300,600,600,10,10);
ggiWmhResize(vis,300,300);
while(!ggi_waitevent(vis)) ggUSleep(50000);
cleanup:
/* Detach extension from visual */
ggiWmhDetach(vis);
/* Close visual */
ggiClose(vis);
/* Deinitialize WMH extension */
ggiWmhExit();
/* Deinitialize LibGGI */
ggiExit();
return 0;
} /* main */
|