summaryrefslogtreecommitdiffstats
path: root/xorg/tests/xdemo
diff options
context:
space:
mode:
Diffstat (limited to 'xorg/tests/xdemo')
-rw-r--r--xorg/tests/xdemo/README.txt2
-rw-r--r--xorg/tests/xdemo/bmp_parser.c60
-rw-r--r--xorg/tests/xdemo/common.h18
-rw-r--r--xorg/tests/xdemo/xdemo.c513
4 files changed, 386 insertions, 207 deletions
diff --git a/xorg/tests/xdemo/README.txt b/xorg/tests/xdemo/README.txt
index 52bda08c..2bb59358 100644
--- a/xorg/tests/xdemo/README.txt
+++ b/xorg/tests/xdemo/README.txt
@@ -1,3 +1,3 @@
-this is a project to develope a program to test xwindows
+this is a program to test xwindows
diff --git a/xorg/tests/xdemo/bmp_parser.c b/xorg/tests/xdemo/bmp_parser.c
index 9d3e43c8..66c050d8 100644
--- a/xorg/tests/xdemo/bmp_parser.c
+++ b/xorg/tests/xdemo/bmp_parser.c
@@ -1,3 +1,21 @@
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Laxmikant Rashinkar 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -50,13 +68,15 @@ int parse_bmp(char *filename, struct pic_info *pic_info)
struct bmp_hdr bmp_hdr;
struct dib_hdr dib_hdr;
- if ((fd = open(filename, O_RDONLY)) < 0) {
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ {
printf("error opeing %s\n", filename);
return -1;
}
// read BMP magic...
- if ((rval = read(fd, magic.magic, 2)) != 2) {
+ if ((rval = read(fd, magic.magic, 2)) != 2)
+ {
fprintf(stderr, "error reading BMP signature from file %s\n", filename);
return -1;
}
@@ -64,44 +84,53 @@ int parse_bmp(char *filename, struct pic_info *pic_info)
got_magic = 0;
// ...and confirm that this is indeed a BMP file
- if ((magic.magic[0] == 'B') && (magic.magic[1] == 'M')) {
+ if ((magic.magic[0] == 'B') && (magic.magic[1] == 'M'))
+ {
// BM – Windows 3.1x, 95, NT, ... etc
got_magic = 1;
}
- else if ((magic.magic[0] == 'B') && (magic.magic[1] == 'A')) {
+ else if ((magic.magic[0] == 'B') && (magic.magic[1] == 'A'))
+ {
// BA – OS/2 struct Bitmap Array
got_magic = 1;
}
- else if ((magic.magic[0] == 'C') && (magic.magic[1] == 'I')) {
+ else if ((magic.magic[0] == 'C') && (magic.magic[1] == 'I'))
+ {
// CI – OS/2 struct Color Icon
got_magic = 1;
}
- else if ((magic.magic[0] == 'C') && (magic.magic[1] == 'P')) {
+ else if ((magic.magic[0] == 'C') && (magic.magic[1] == 'P'))
+ {
// CP – OS/2 const Color Pointer
got_magic = 1;
}
- else if ((magic.magic[0] == 'I') && (magic.magic[1] == 'C')) {
+ else if ((magic.magic[0] == 'I') && (magic.magic[1] == 'C'))
+ {
// IC – OS/2 struct Icon
got_magic = 1;
}
- else if ((magic.magic[0] == 'P') && (magic.magic[1] == 'T')) {
+ else if ((magic.magic[0] == 'P') && (magic.magic[1] == 'T'))
+ {
// PT – OS/2 Pointer
got_magic = 1;
}
- if (!got_magic) {
+ if (!got_magic)
+ {
fprintf(stderr, "%s is not a valid BMP file\n", filename);
return -1;
}
// read BMP header
- if ((rval = read(fd, &bmp_hdr, sizeof(bmp_hdr))) < sizeof(bmp_hdr)) {
+ if ((rval = read(fd, &bmp_hdr, sizeof(bmp_hdr))) < sizeof(bmp_hdr))
+ {
fprintf(stderr, "error BMP header from file %s\n", filename);
return -1;
}
// read DIB header
- if ((rval = read(fd, &dib_hdr, sizeof(dib_hdr))) < sizeof(dib_hdr)) {
+ if ((rval = read(fd, &dib_hdr, sizeof(dib_hdr))) < sizeof(dib_hdr))
+ {
fprintf(stderr, "error reading DIB header from file %s\n", filename);
return -1;
}
@@ -120,7 +149,8 @@ int parse_bmp(char *filename, struct pic_info *pic_info)
printf("nimpcolors: %d\n", dib_hdr.nimpcolors);
#endif
- if (dib_hdr.compress_type) {
+ if (dib_hdr.compress_type)
+ {
printf("TODO: compressed images not yet supported\n");
return -1;
}
@@ -128,9 +158,11 @@ int parse_bmp(char *filename, struct pic_info *pic_info)
pic_info->width = dib_hdr.width;
pic_info->height = dib_hdr.height;
- if (dib_hdr.bpp == 24) {
+ if (dib_hdr.bpp == 24)
+ {
rval = parse_bmp_24(&bmp_hdr, &dib_hdr, fd, pic_info);
}
+
close(fd);
return rval;
}
@@ -189,6 +221,7 @@ int parse_bmp_24(
for (i = 0; i < h; i ++)
{
cptr = ptr_file_data;
+
for (j = 0; j < w; j++)
{
*ptr_mem_data++ = *cptr++; // blue value
@@ -196,6 +229,7 @@ int parse_bmp_24(
*ptr_mem_data++ = *cptr++; // red value
*ptr_mem_data++ = 0; // alpha channel
}
+
ptr_file_data -= bpl;
}
diff --git a/xorg/tests/xdemo/common.h b/xorg/tests/xdemo/common.h
index 2ce75bba..8ed4ee65 100644
--- a/xorg/tests/xdemo/common.h
+++ b/xorg/tests/xdemo/common.h
@@ -1,3 +1,21 @@
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Laxmikant Rashinkar 2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef __XDEMO_H
#define __XDEMO_H
diff --git a/xorg/tests/xdemo/xdemo.c b/xorg/tests/xdemo/xdemo.c
index 01bd248e..f7e6b0ef 100644
--- a/xorg/tests/xdemo/xdemo.c
+++ b/xorg/tests/xdemo/xdemo.c
@@ -1,3 +1,21 @@
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Laxmikant Rashinkar 2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -78,7 +96,8 @@ int drawLines(int count)
int i;
int index;
- if (count <= 0) {
+ if (count <= 0)
+ {
return 0; // nothing to do
}
@@ -92,14 +111,18 @@ int drawLines(int count)
x2 = random() % g_winWidth;
y2 = random() % g_winHeight;
XSetForeground(g_disp, g_gc, g_colors[index++].pixel);
- if (index == MAX_COLORS) {
+
+ if (index == MAX_COLORS)
+ {
index = 0;
}
+
// from-to
XDrawLine(g_disp, g_win, g_gc, x1, y1, x2, y2);
XFlush(g_disp);
usleep(g_delay_dur);
}
+
return 0;
}
@@ -114,7 +137,8 @@ int drawRectangles(int count)
int i;
int index;
- if (count <= 0) {
+ if (count <= 0)
+ {
return 0; // nothing to do
}
@@ -128,14 +152,18 @@ int drawRectangles(int count)
w = 160;
h = 140;
XSetForeground(g_disp, g_gc, g_colors[index++].pixel);
- if (index == MAX_COLORS) {
+
+ if (index == MAX_COLORS)
+ {
index = 0;
}
+
//XDrawRectangle(g_disp, g_win, g_gc, x1, y1, w, h);
XFillRectangle(g_disp, g_win, g_gc, x1, y1, w, h);
XFlush(g_disp);
usleep(g_delay_dur);
}
+
return 0;
}
@@ -153,7 +181,8 @@ int drawFont(int count, char *msg)
char **font_list;
#endif
- if (count <= 0) {
+ if (count <= 0)
+ {
return 0; // nothing to do
}
@@ -162,17 +191,23 @@ int drawFont(int count, char *msg)
#ifdef CHANGE_FONT_SIZE
font_list = XListFonts(g_disp, "−*−courier−*−*−*−*−0−0−*−*−*−0−*−*", 2000, &actual_count);
- if (!font_list) {
+
+ if (!font_list)
+ {
printf("actual_count=%d\n", actual_count);
+
for (i = 0; i < actual_count; i++)
{
printf("%s\n", font_list[i]);
}
+
XFreeFontNames(font_list);
}
- else {
+ else
+ {
printf("XListFonts() reted NULL\n");
}
+
#endif
srandom(time(NULL));
@@ -182,13 +217,17 @@ int drawFont(int count, char *msg)
x1 = random() % g_winWidth;
y1 = random() % g_winHeight;
XSetForeground(g_disp, g_gc, g_colors[index++].pixel);
- if (index == MAX_COLORS) {
+
+ if (index == MAX_COLORS)
+ {
index = 0;
}
+
XDrawString(g_disp, g_win, g_gc, x1, y1, msg, strlen(msg));
XFlush(g_disp);
usleep(g_delay_dur);
}
+
return 0; // nothing to do
}
@@ -244,7 +283,7 @@ usage(void)
}
int
-main(int argc, char** argv)
+main(int argc, char **argv)
{
XEvent evt;
Colormap colormap;
@@ -286,160 +325,190 @@ main(int argc, char** argv)
// process cmd line args
opterr = 0;
+
while ((opt = getopt(argc, argv, "lrsjg:c:f:i:d:o:z:")) != -1)
{
switch (opt)
{
-
- case 'j':
- draw_lines = 0;
- draw_rects = 0;
- draw_stipples = 0;
- draw_fonts = 0;
- draw_image = 0;
- draw_offscreen = 1;
- break;
-
- case 'g':
- if (sscanf(optarg, "%dx%d", &g_winWidth, &g_winHeight) != 2) {
- fprintf(stderr, "\nerror: invalid geometry specified\n\n");
- usage();
- return -1;
- }
- break;
-
- case 'c':
- if (sscanf(optarg, "%d", &iters) != 1) {
- fprintf(stderr, "\nerror: invalid count specified\n\n");
- usage();
- return -1;
- }
- break;
-
- case 'l':
- draw_lines = 1;
- draw_rects = 0;
- draw_stipples = 0;
- draw_fonts = 0;
- draw_image = 0;
- draw_offscreen = 0;
- break;
-
- case 'r':
- draw_rects = 1;
- draw_lines = 0;
- draw_stipples = 0;
- draw_fonts = 0;
- draw_image = 0;
- draw_offscreen = 0;
- break;
-
- case 's':
- draw_stipples = 1;
- draw_lines = 0;
- draw_rects = 0;
- draw_fonts = 0;
- draw_image = 0;
- draw_offscreen = 0;
- break;
-
- case 'f':
- if (strlen(optarg) <= 0) {
- fprintf(stderr, "\nerror: -f option requires an argument\n\n");
- usage();
- return -1;
- }
- draw_fonts = 1;
- strncpy(msg, optarg, 4096);
- draw_lines = 0;
- draw_rects = 0;
- draw_stipples = 0;
- draw_image = 0;
- draw_offscreen = 0;
- break;
-
- case 'i':
- if (strlen(optarg) <= 0) {
- fprintf(stderr, "\nerror: -i option requires an argument\n\n");
- usage();
- return -1;
- }
- draw_image = 1;
- strncpy(image_file, optarg, 255);
- draw_lines = 0;
- draw_rects = 0;
- draw_stipples = 0;
- draw_fonts = 0;
- draw_offscreen= 0;
- break;
-
- case 'h':
- usage();
- return 0;
- break;
-
- case 'v':
- printf("xdemo Ver 1.0\n");
- return 0;
- break;
-
- case 'd':
- if (sscanf(optarg, "%d", &g_delay_dur) != 1) {
- fprintf(stderr, "\nerror: -d option requires an argument\n\n");
- usage();
- return -1;
- }
- break;
- case 'z':
- if (strlen(optarg) <= 0) {
- fprintf(stderr, "\nerror: invalid proxy application specified\n\n");
+ case 'j':
+ draw_lines = 0;
+ draw_rects = 0;
+ draw_stipples = 0;
+ draw_fonts = 0;
+ draw_image = 0;
+ draw_offscreen = 1;
+ break;
+
+ case 'g':
+
+ if (sscanf(optarg, "%dx%d", &g_winWidth, &g_winHeight) != 2)
+ {
+ fprintf(stderr, "\nerror: invalid geometry specified\n\n");
+ usage();
+ return -1;
+ }
+
+ break;
+
+ case 'c':
+
+ if (sscanf(optarg, "%d", &iters) != 1)
+ {
+ fprintf(stderr, "\nerror: invalid count specified\n\n");
+ usage();
+ return -1;
+ }
+
+ break;
+
+ case 'l':
+ draw_lines = 1;
+ draw_rects = 0;
+ draw_stipples = 0;
+ draw_fonts = 0;
+ draw_image = 0;
+ draw_offscreen = 0;
+ break;
+
+ case 'r':
+ draw_rects = 1;
+ draw_lines = 0;
+ draw_stipples = 0;
+ draw_fonts = 0;
+ draw_image = 0;
+ draw_offscreen = 0;
+ break;
+
+ case 's':
+ draw_stipples = 1;
+ draw_lines = 0;
+ draw_rects = 0;
+ draw_fonts = 0;
+ draw_image = 0;
+ draw_offscreen = 0;
+ break;
+
+ case 'f':
+
+ if (strlen(optarg) <= 0)
+ {
+ fprintf(stderr, "\nerror: -f option requires an argument\n\n");
+ usage();
+ return -1;
+ }
+
+ draw_fonts = 1;
+ strncpy(msg, optarg, 4096);
+ draw_lines = 0;
+ draw_rects = 0;
+ draw_stipples = 0;
+ draw_image = 0;
+ draw_offscreen = 0;
+ break;
+
+ case 'i':
+
+ if (strlen(optarg) <= 0)
+ {
+ fprintf(stderr, "\nerror: -i option requires an argument\n\n");
+ usage();
+ return -1;
+ }
+
+ draw_image = 1;
+ strncpy(image_file, optarg, 255);
+ draw_lines = 0;
+ draw_rects = 0;
+ draw_stipples = 0;
+ draw_fonts = 0;
+ draw_offscreen = 0;
+ break;
+
+ case 'h':
usage();
- return -1;
- }
- strcpy(proxy_app, optarg);
- printf("##### LK_TODO: proxy_app=%s\n", proxy_app);
- zero_counters = 1;
- break;
-
- case 'o':
- if (strcmp(optarg, "jump") == 0) {
- scroll_type = SCROLL_JUMP;
- }
- else if (strcmp(optarg, "smooth1") == 0) {
- scroll_type = SCROLL_SMOOTH1;
- }
- else if (strcmp(optarg, "smooth2") == 0) {
- scroll_type = SCROLL_SMOOTH2;
- }
- else if (strcmp(optarg, "smooth3") == 0) {
- scroll_type = SCROLL_SMOOTH3;
- }
- else if (strcmp(optarg, "smooth4") == 0) {
- scroll_type = SCROLL_SMOOTH4;
- }
- else {
- fprintf(stderr, "\ninvalid scroll type specified\n\n");
+ return 0;
+ break;
+
+ case 'v':
+ printf("xdemo Ver 1.0\n");
+ return 0;
+ break;
+
+ case 'd':
+
+ if (sscanf(optarg, "%d", &g_delay_dur) != 1)
+ {
+ fprintf(stderr, "\nerror: -d option requires an argument\n\n");
+ usage();
+ return -1;
+ }
+
+ break;
+
+ case 'z':
+
+ if (strlen(optarg) <= 0)
+ {
+ fprintf(stderr, "\nerror: invalid proxy application specified\n\n");
+ usage();
+ return -1;
+ }
+
+ strcpy(proxy_app, optarg);
+ printf("##### LK_TODO: proxy_app=%s\n", proxy_app);
+ zero_counters = 1;
+ break;
+
+ case 'o':
+
+ if (strcmp(optarg, "jump") == 0)
+ {
+ scroll_type = SCROLL_JUMP;
+ }
+ else if (strcmp(optarg, "smooth1") == 0)
+ {
+ scroll_type = SCROLL_SMOOTH1;
+ }
+ else if (strcmp(optarg, "smooth2") == 0)
+ {
+ scroll_type = SCROLL_SMOOTH2;
+ }
+ else if (strcmp(optarg, "smooth3") == 0)
+ {
+ scroll_type = SCROLL_SMOOTH3;
+ }
+ else if (strcmp(optarg, "smooth4") == 0)
+ {
+ scroll_type = SCROLL_SMOOTH4;
+ }
+ else
+ {
+ fprintf(stderr, "\ninvalid scroll type specified\n\n");
+ usage();
+ return -1;
+ }
+
+ break;
+
+ default:
usage();
return -1;
- }
- break;
-
- default:
- usage();
- return -1;
}
}
// must have at least one operation
if ((!draw_lines) && (!draw_rects) && (!draw_stipples) &&
- (!draw_fonts) && (!draw_image) && (!draw_offscreen)) {
+ (!draw_fonts) && (!draw_image) && (!draw_offscreen))
+ {
usage();
return -1;
}
g_disp = XOpenDisplay(NULL);
- if (!g_disp) {
+
+ if (!g_disp)
+ {
dprint("error opening X display\n");
exit(-1);
}
@@ -461,88 +530,114 @@ main(int argc, char** argv)
XSelectInput(g_disp, g_win, eventMask);
g_gc = XCreateGC(g_disp, g_win,
- 0, // mask of values
- NULL ); // array of values
- #if 0
+ 0, // mask of values
+ NULL ); // array of values
+#if 0
+
do
{
dprint("about to call XNextEvent(...)\n");
XNextEvent(g_disp, &evt);// calls XFlush
dprint("returned from XNextEvent(...)\n");
}
+
//while(evt.type != MapNotify);
- while(evt.type != VisibilityNotify);
- #endif
+ while (evt.type != VisibilityNotify)
+ {
+ ;
+ }
+
+#endif
// get access to the screen's color map
colormap = DefaultColormap(g_disp, screenNumber);
// alloc red color
rc = XAllocNamedColor(g_disp, colormap, "red", &g_colors[0], &g_colors[0]);
- if (rc == 0) {
+
+ if (rc == 0)
+ {
printf("XAllocNamedColor - failed to allocated 'red' color.\n");
exit(1);
}
rc = XAllocNamedColor(g_disp, colormap, "green", &g_colors[1], &g_colors[1]);
- if (rc == 0) {
+
+ if (rc == 0)
+ {
printf("XAllocNamedColor - failed to allocated 'green' color.\n");
exit(1);
}
rc = XAllocNamedColor(g_disp, colormap, "blue", &g_colors[2], &g_colors[2]);
- if (rc == 0) {
+
+ if (rc == 0)
+ {
printf("XAllocNamedColor - failed to allocated 'blue' color.\n");
exit(1);
}
+
rc = XAllocNamedColor(g_disp, colormap, "yellow", &g_colors[3], &g_colors[3]);
- if (rc == 0) {
+
+ if (rc == 0)
+ {
printf("XAllocNamedColor - failed to allocated 'yellow' color.\n");
exit(1);
}
+
rc = XAllocNamedColor(g_disp, colormap, "orange", &g_colors[4], &g_colors[4]);
- if (rc == 0) {
+
+ if (rc == 0)
+ {
printf("XAllocNamedColor - failed to allocated 'orange' color.\n");
exit(1);
}
- if (zero_counters) {
+ if (zero_counters)
+ {
signal_tcp_proxy(proxy_app);
}
- if (draw_lines) {
+ if (draw_lines)
+ {
start_timer(&tv);
drawLines(iters);
printf("drew %d lines in %d ms\n", iters, time_elapsed_ms(tv));
}
- if (draw_rects) {
+ if (draw_rects)
+ {
start_timer(&tv);
drawRectangles(iters);
printf("drew %d rects in %d ms\n", iters, time_elapsed_ms(tv));
}
- if (draw_stipples) {
+ if (draw_stipples)
+ {
start_timer(&tv);
// LK_TODO
}
- if (draw_fonts) {
+ if (draw_fonts)
+ {
start_timer(&tv);
- drawFont(iters, msg);
+ drawFont(iters, msg);
printf("drew %d strings in %d ms\n", iters, time_elapsed_ms(tv));
}
- if (draw_image) {
+ if (draw_image)
+ {
start_timer(&tv);
drawBMP(image_file, scroll_type);
printf("drew BMP in %d ms\n", time_elapsed_ms(tv));
}
-
- if (draw_offscreen) {
+
+ if (draw_offscreen)
+ {
}
- if (zero_counters) {
+ if (zero_counters)
+ {
signal_tcp_proxy(proxy_app);
}
@@ -553,12 +648,15 @@ main(int argc, char** argv)
do
{
XNextEvent(g_disp, &evt); // calls XFlush()
- if (evt.type == KeyPress) {
- if (draw_offscreen) {
+
+ if (evt.type == KeyPress)
+ {
+ if (draw_offscreen)
+ {
drawoffscreen();
}
}
-
+
}
while (evt.type != ButtonRelease);
@@ -578,9 +676,11 @@ int drawBMP(char *filename, int scroll_type)
int i;
int j;
- if (parse_bmp(filename, &pic_info) < 0) {
+ if (parse_bmp(filename, &pic_info) < 0)
+ {
exit(-1);
}
+
XClearArea(g_disp, g_win, 0, 0, g_winWidth, g_winHeight, 0);
depth = DefaultDepth(g_disp, DefaultScreen(g_disp));
@@ -593,7 +693,8 @@ int drawBMP(char *filename, int scroll_type)
image = XCreateImage(g_disp, visual, depth, ZPixmap, 0, pic_info.pixel_data,
pic_info.width, pic_info.height, 32, 0);
- if (pic_info.height <= g_winHeight) {
+ if (pic_info.height <= g_winHeight)
+ {
// image is too small to scroll
XFlush(g_disp);
XPutImage(g_disp, g_win, g_gc, image, 0, 0, 0, 0, pic_info.width, pic_info.height);
@@ -604,9 +705,11 @@ int drawBMP(char *filename, int scroll_type)
// copy image to pixelmap
XPutImage(g_disp, pixmap, g_gc, image, 0, 0, 0, 0, pic_info.width, pic_info.height);
- if (scroll_type == SCROLL_JUMP) {
+ if (scroll_type == SCROLL_JUMP)
+ {
- if (pic_info.height <= g_winHeight) {
+ if (pic_info.height <= g_winHeight)
+ {
// image too small - no scrolling required
XFlush(g_disp);
XCopyArea(g_disp, // connection to X server
@@ -622,11 +725,15 @@ int drawBMP(char *filename, int scroll_type)
}
j = pic_info.height / g_winHeight;
- if (pic_info.height % g_winHeight != 0) {
+
+ if (pic_info.height % g_winHeight != 0)
+ {
// need to include the last part of the image
j++;
}
+
XFlush(g_disp);
+
for (i = 0; i < j; i++)
{
XCopyArea(g_disp, // connection to X server
@@ -649,25 +756,30 @@ int drawBMP(char *filename, int scroll_type)
// number of lines to be scrolled
j = pic_info.height - g_winHeight;
- if (scroll_type == SCROLL_SMOOTH1) {
+ if (scroll_type == SCROLL_SMOOTH1)
+ {
printf("running SCROLL_SMOOTH1\n");
XFlush(g_disp);
XPutImage(g_disp, g_win, g_gc, image, 0, 0, 0, 0, pic_info.width, pic_info.height);
XFlush(g_disp);
usleep(10000);
+
for (i = 0; i < j; i++)
{
XCopyArea(g_disp, g_win, g_win, g_gc, 0, 1, g_winWidth, g_winHeight - 1, 0, 0);
- XPutImage(g_disp, g_win, g_gc, image, 0, g_winHeight + i, 0, g_winHeight -1 , pic_info.width, 1);
+ XPutImage(g_disp, g_win, g_gc, image, 0, g_winHeight + i, 0, g_winHeight - 1 , pic_info.width, 1);
XFlush(g_disp);
usleep(10000);
}
+
return 0;
}
- if (scroll_type == SCROLL_SMOOTH2) {
+ if (scroll_type == SCROLL_SMOOTH2)
+ {
printf("running SCROLL_SMOOTH2\n");
XFlush(g_disp);
+
for (i = 0; i < j; i++)
{
XPutImage(g_disp, g_win, g_gc, image, 0, i, 0, 0, pic_info.width, pic_info.height - i);
@@ -675,25 +787,31 @@ int drawBMP(char *filename, int scroll_type)
usleep(10000);
}
}
- if (scroll_type == SCROLL_SMOOTH3) {
+
+ if (scroll_type == SCROLL_SMOOTH3)
+ {
printf("running SCROLL_SMOOTH3\n");
XFlush(g_disp);
XCopyArea(g_disp, pixmap, g_win, g_gc, 0, 0, pic_info.width, pic_info.height, 0, 0);
XFlush(g_disp);
usleep(10000);
+
for (i = 0; i < j; i++)
{
XCopyArea(g_disp, g_win, g_win, g_gc, 0, 1, g_winWidth, g_winHeight - 1, 0, 0);
- XCopyArea(g_disp, pixmap, g_win, g_gc, 0, g_winHeight + i, pic_info.width, 1, 0, g_winHeight -1);
+ XCopyArea(g_disp, pixmap, g_win, g_gc, 0, g_winHeight + i, pic_info.width, 1, 0, g_winHeight - 1);
XFlush(g_disp);
usleep(10000);
}
+
return 0;
}
- if (scroll_type == SCROLL_SMOOTH4) {
+ if (scroll_type == SCROLL_SMOOTH4)
+ {
printf("running SCROLL_SMOOTH4\n");
XFlush(g_disp);
+
for (i = 0; i < j; i++)
{
XCopyArea(g_disp, pixmap, g_win, g_gc, 0, i, pic_info.width, pic_info.height - i, 0, 0);
@@ -710,19 +828,21 @@ int process_bmp_event()
XEvent ev;
long event_mask;
- event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask|StructureNotifyMask;
+ event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask;
XSelectInput(g_disp, g_win, event_mask);
XNextEvent(g_disp, &ev);
- switch(ev.type)
+
+ switch (ev.type)
{
- case Expose:
- printf("got expose event\n");
- break;
+ case Expose:
+ printf("got expose event\n");
+ break;
- default:
- printf("did not get expose event\n");
- break;
+ default:
+ printf("did not get expose event\n");
+ break;
}
+
return 0;
}
@@ -743,22 +863,29 @@ int signal_tcp_proxy(char *proc_name)
int i;
sprintf(buf, "pidof %s", proc_name);
- if ((fp = popen(buf, "r")) == NULL ) {
+
+ if ((fp = popen(buf, "r")) == NULL )
+ {
printf("xdemo: popen() failed\n");
return -1;
}
cptr = fgets(buf, 2047, fp);
- if (cptr == NULL) {
+
+ if (cptr == NULL)
+ {
pclose(fp);
return -1;
}
- num_procs = sscanf(buf, "%d %d %d %d %d %d %d %d %d %d",
- &pids[0], &pids[1], &pids[2], &pids[3], &pids[4],
+ num_procs = sscanf(buf, "%d %d %d %d %d %d %d %d %d %d",
+ &pids[0], &pids[1], &pids[2], &pids[3], &pids[4],
&pids[5], &pids[6], &pids[7], &pids[8], &pids[9]);
- if (num_procs > 0) {
- for (i = 0; i < num_procs; i++) {
+
+ if (num_procs > 0)
+ {
+ for (i = 0; i < num_procs; i++)
+ {
kill(pids[i], SIGUSR1);
printf("sent SIGUSR1 to process %d\n", pids[i]);
}