Merging back tools directory from kwin_iii to HEAD.
svn path=/trunk/kdebase/kwin/; revision=251613
This commit is contained in:
parent
f8b2ceee53
commit
1ffd659717
10 changed files with 2674 additions and 0 deletions
9
tools/Makefile.am
Normal file
9
tools/Makefile.am
Normal file
|
@ -0,0 +1,9 @@
|
|||
noinst_PROGRAMS = test_gravity
|
||||
|
||||
INCLUDES = $(all_includes)
|
||||
|
||||
test_gravity_SOURCES = test_gravity.cpp
|
||||
test_gravity_LDFLAGS = $(all_libraries) $(KDE_RPATH)
|
||||
test_gravity_LDADD = $(LIB_X11)
|
||||
|
||||
METASOURCES = AUTO
|
85
tools/test_gravity.cpp
Normal file
85
tools/test_gravity.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
// tests for window gravity
|
||||
|
||||
#define INITIAL_POSITION_TEST
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int gravities[ 10 ] =
|
||||
{
|
||||
NorthWestGravity,
|
||||
NorthGravity,
|
||||
NorthEastGravity,
|
||||
WestGravity,
|
||||
CenterGravity,
|
||||
EastGravity,
|
||||
SouthWestGravity,
|
||||
SouthGravity,
|
||||
SouthEastGravity,
|
||||
StaticGravity
|
||||
};
|
||||
|
||||
const char* const gravity_names[ 10 ] =
|
||||
{
|
||||
"NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
|
||||
};
|
||||
|
||||
Display* dpy = NULL;
|
||||
|
||||
int get_gravity( const char* name )
|
||||
{
|
||||
for( int i = 0;
|
||||
i < 10;
|
||||
++i )
|
||||
if( strcmp( name, gravity_names[ i ] ) == 0 )
|
||||
return gravities[ i ];
|
||||
cerr << "Wrong gravity name" << endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
void initial_position_test( const char* gravity )
|
||||
{
|
||||
XSetWindowAttributes attrs;
|
||||
XSizeHints hints;
|
||||
hints.flags = USPosition | PWinGravity;
|
||||
hints.win_gravity = get_gravity( gravity );
|
||||
Window w = XCreateWindow( dpy, DefaultRootWindow( dpy ), 100, 100, 200, 100, 0, CopyFromParent, CopyFromParent,
|
||||
CopyFromParent, 0, &attrs );
|
||||
XSetWMNormalHints( dpy, w, &hints );
|
||||
XSelectInput( dpy, w, StructureNotifyMask );
|
||||
XMapWindow( dpy, w );
|
||||
for(;;)
|
||||
{
|
||||
XEvent ev;
|
||||
XNextEvent( dpy, &ev );
|
||||
if( ev.type == ConfigureNotify )
|
||||
{
|
||||
cout << "CONFIGURENOTIFY:" << ev.xany.send_event << ":" << ev.xconfigure.x << ":" << ev.xconfigure.y
|
||||
<< ":" << ev.xconfigure.width << ":" << ev.xconfigure.height << endl;
|
||||
Window root, child;
|
||||
int x, x_local, y, y_local;
|
||||
unsigned int width, height, border, depth;
|
||||
XGetGeometry( dpy, w, &root, &x_local, &y_local, &width, &height, &border, &depth );
|
||||
XTranslateCoordinates( dpy, w, root, 0, 0, &x, &y, &child );
|
||||
cout << "GEOMETRY:" << x << ":" << y << ":" << width << ":" << height << ":(" << x_local << ":" << y_local << ")" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
dpy = XOpenDisplay( NULL );
|
||||
#ifdef INITIAL_POSITION_TEST
|
||||
if( argc != 2 )
|
||||
{
|
||||
cerr << "specify gravity" << endl;
|
||||
exit( 1 );
|
||||
}
|
||||
initial_position_test( argv[ 1 ] );
|
||||
#endif
|
||||
XCloseDisplay( dpy );
|
||||
}
|
2
tools/xprop/Makefile
Normal file
2
tools/xprop/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
gcc dsimple.c xprop.c -o xprop -lXmu -lX11 -L/usr/X11R6/lib
|
1
tools/xprop/README
Normal file
1
tools/xprop/README
Normal file
|
@ -0,0 +1 @@
|
|||
patched xprop that shows all WINDOW elements in properties, not just the first one
|
521
tools/xprop/dsimple.c
Normal file
521
tools/xprop/dsimple.c
Normal file
|
@ -0,0 +1,521 @@
|
|||
/* $Xorg: dsimple.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
|
||||
/*
|
||||
|
||||
Copyright 1993, 1998 The Open Group
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided that
|
||||
the above copyright notice appear in all copies and that both that
|
||||
copyright notice and this permission notice appear in supporting
|
||||
documentation.
|
||||
|
||||
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 OPEN GROUP 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.
|
||||
|
||||
Except as contained in this notice, the name of The Open Group shall
|
||||
not be used in advertising or otherwise to promote the sale, use or
|
||||
other dealings in this Software without prior written authorization
|
||||
from The Open Group.
|
||||
|
||||
*/
|
||||
/* $XFree86: xc/programs/xlsfonts/dsimple.c,v 3.6 2001/12/14 20:02:09 dawes Exp $ */
|
||||
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
/*
|
||||
* Other_stuff.h: Definitions of routines in other_stuff.
|
||||
*
|
||||
* Written by Mark Lillibridge. Last updated 7/1/87
|
||||
*/
|
||||
|
||||
#include "dsimple.h"
|
||||
|
||||
/*
|
||||
* Just_display: A group of routines designed to make the writting of simple
|
||||
* X11 applications which open a display but do not open
|
||||
* any windows much faster and easier. Unless a routine says
|
||||
* otherwise, it may be assumed to require program_name, dpy,
|
||||
* and screen already defined on entry.
|
||||
*
|
||||
* Written by Mark Lillibridge. Last updated 7/1/87
|
||||
*/
|
||||
|
||||
|
||||
/* This stuff is defined in the calling program by just_display.h */
|
||||
char *program_name = "unknown_program";
|
||||
Display *dpy;
|
||||
int screen;
|
||||
|
||||
static void _bitmap_error(int, char *);
|
||||
|
||||
/*
|
||||
* Malloc: like malloc but handles out of memory using Fatal_Error.
|
||||
*/
|
||||
char *Malloc(size)
|
||||
unsigned size;
|
||||
{
|
||||
char *data;
|
||||
|
||||
if (!(data = malloc(size)))
|
||||
Fatal_Error("Out of memory!");
|
||||
|
||||
return(data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Realloc: like Malloc except for realloc, handles NULL using Malloc.
|
||||
*/
|
||||
char *Realloc(ptr, size)
|
||||
char *ptr;
|
||||
int size;
|
||||
{
|
||||
char *new_ptr;
|
||||
|
||||
if (!ptr)
|
||||
return(Malloc(size));
|
||||
|
||||
if (!(new_ptr = realloc(ptr, size)))
|
||||
Fatal_Error("Out of memory!");
|
||||
|
||||
return(new_ptr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
|
||||
* If found, remove it from command line. Don't go past a lone -.
|
||||
*/
|
||||
char *Get_Display_Name(pargc, argv)
|
||||
int *pargc; /* MODIFIED */
|
||||
char **argv; /* MODIFIED */
|
||||
{
|
||||
int argc = *pargc;
|
||||
char **pargv = argv+1;
|
||||
char *displayname = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
char *arg = argv[i];
|
||||
|
||||
if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
|
||||
if (++i >= argc) usage ();
|
||||
|
||||
displayname = argv[i];
|
||||
*pargc -= 2;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg,"-")) {
|
||||
while (i<argc)
|
||||
*pargv++ = argv[i++];
|
||||
break;
|
||||
}
|
||||
*pargv++ = arg;
|
||||
}
|
||||
|
||||
*pargv = NULL;
|
||||
return (displayname);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Open_Display: Routine to open a display with correct error handling.
|
||||
* Does not require dpy or screen defined on entry.
|
||||
*/
|
||||
Display *Open_Display(display_name)
|
||||
char *display_name;
|
||||
{
|
||||
Display *d;
|
||||
|
||||
d = XOpenDisplay(display_name);
|
||||
if (d == NULL) {
|
||||
fprintf (stderr, "%s: unable to open display '%s'\n",
|
||||
program_name, XDisplayName (display_name));
|
||||
usage ();
|
||||
/* doesn't return */
|
||||
}
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Setup_Display_And_Screen: This routine opens up the correct display (i.e.,
|
||||
* it calls Get_Display_Name) and then stores a
|
||||
* pointer to it in dpy. The default screen
|
||||
* for this display is then stored in screen.
|
||||
* Does not require dpy or screen defined.
|
||||
*/
|
||||
void Setup_Display_And_Screen(argc, argv)
|
||||
int *argc; /* MODIFIED */
|
||||
char **argv; /* MODIFIED */
|
||||
{
|
||||
dpy = Open_Display (Get_Display_Name(argc, argv));
|
||||
screen = DefaultScreen(dpy);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Open_Font: This routine opens a font with error handling.
|
||||
*/
|
||||
XFontStruct *Open_Font(name)
|
||||
char *name;
|
||||
{
|
||||
XFontStruct *font;
|
||||
|
||||
if (!(font=XLoadQueryFont(dpy, name)))
|
||||
Fatal_Error("Unable to open font %s!", name);
|
||||
|
||||
return(font);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Beep: Routine to beep the display.
|
||||
*/
|
||||
void Beep()
|
||||
{
|
||||
XBell(dpy, 50);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ReadBitmapFile: same as XReadBitmapFile except it returns the bitmap
|
||||
* directly and handles errors using Fatal_Error.
|
||||
*/
|
||||
static void _bitmap_error(status, filename)
|
||||
int status;
|
||||
char *filename;
|
||||
{
|
||||
if (status == BitmapOpenFailed)
|
||||
Fatal_Error("Can't open file %s!", filename);
|
||||
else if (status == BitmapFileInvalid)
|
||||
Fatal_Error("file %s: Bad bitmap format.", filename);
|
||||
else
|
||||
Fatal_Error("Out of memory!");
|
||||
}
|
||||
|
||||
Pixmap ReadBitmapFile(d, filename, width, height, x_hot, y_hot)
|
||||
Drawable d;
|
||||
char *filename;
|
||||
int *width, *height, *x_hot, *y_hot;
|
||||
{
|
||||
Pixmap bitmap;
|
||||
int status;
|
||||
|
||||
status = XReadBitmapFile(dpy, RootWindow(dpy, screen), filename,
|
||||
(unsigned int *)width, (unsigned int *)height,
|
||||
&bitmap, x_hot, y_hot);
|
||||
if (status != BitmapSuccess)
|
||||
_bitmap_error(status, filename);
|
||||
|
||||
return(bitmap);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* WriteBitmapFile: same as XWriteBitmapFile except it handles errors
|
||||
* using Fatal_Error.
|
||||
*/
|
||||
void WriteBitmapFile(filename, bitmap, width, height, x_hot, y_hot)
|
||||
char *filename;
|
||||
Pixmap bitmap;
|
||||
int width, height, x_hot, y_hot;
|
||||
{
|
||||
int status;
|
||||
|
||||
status= XWriteBitmapFile(dpy, filename, bitmap, width, height, x_hot,
|
||||
y_hot);
|
||||
if (status != BitmapSuccess)
|
||||
_bitmap_error(status, filename);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Select_Window_Args: a rountine to provide a common interface for
|
||||
* applications that need to allow the user to select one
|
||||
* window on the screen for special consideration.
|
||||
* This routine implements the following command line
|
||||
* arguments:
|
||||
*
|
||||
* -root Selects the root window.
|
||||
* -id <id> Selects window with id <id>. <id> may
|
||||
* be either in decimal or hex.
|
||||
* -name <name> Selects the window with name <name>.
|
||||
*
|
||||
* Call as Select_Window_Args(&argc, argv) in main before
|
||||
* parsing any of your program's command line arguments.
|
||||
* Select_Window_Args will remove its arguments so that
|
||||
* your program does not have to worry about them.
|
||||
* The window returned is the window selected or 0 if
|
||||
* none of the above arguments was present. If 0 is
|
||||
* returned, Select_Window should probably be called after
|
||||
* all command line arguments, and other setup is done.
|
||||
* For examples of usage, see xwininfo, xwd, or xprop.
|
||||
*/
|
||||
Window Select_Window_Args(rargc, argv)
|
||||
int *rargc;
|
||||
char **argv;
|
||||
#define ARGC (*rargc)
|
||||
{
|
||||
int nargc=1;
|
||||
int argc;
|
||||
char **nargv;
|
||||
Window w=0;
|
||||
|
||||
nargv = argv+1; argc = ARGC;
|
||||
#define OPTION argv[0]
|
||||
#define NXTOPTP ++argv, --argc>0
|
||||
#define NXTOPT if (++argv, --argc==0) usage()
|
||||
#define COPYOPT nargv++[0]=OPTION, nargc++
|
||||
|
||||
while (NXTOPTP) {
|
||||
if (!strcmp(OPTION, "-")) {
|
||||
COPYOPT;
|
||||
while (NXTOPTP)
|
||||
COPYOPT;
|
||||
break;
|
||||
}
|
||||
if (!strcmp(OPTION, "-root")) {
|
||||
w=RootWindow(dpy, screen);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(OPTION, "-name")) {
|
||||
NXTOPT;
|
||||
w = Window_With_Name(dpy, RootWindow(dpy, screen),
|
||||
OPTION);
|
||||
if (!w)
|
||||
Fatal_Error("No window with name %s exists!",OPTION);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(OPTION, "-id")) {
|
||||
NXTOPT;
|
||||
w=0;
|
||||
sscanf(OPTION, "0x%lx", &w);
|
||||
if (!w)
|
||||
sscanf(OPTION, "%ld", &w);
|
||||
if (!w)
|
||||
Fatal_Error("Invalid window id format: %s.", OPTION);
|
||||
continue;
|
||||
}
|
||||
COPYOPT;
|
||||
}
|
||||
ARGC = nargc;
|
||||
|
||||
return(w);
|
||||
}
|
||||
|
||||
/*
|
||||
* Other_stuff: A group of routines which do common X11 tasks.
|
||||
*
|
||||
* Written by Mark Lillibridge. Last updated 7/1/87
|
||||
*/
|
||||
|
||||
/*
|
||||
* Resolve_Color: This routine takes a color name and returns the pixel #
|
||||
* that when used in the window w will be of color name.
|
||||
* (WARNING: The colormap of w MAY be modified! )
|
||||
* If colors are run out of, only the first n colors will be
|
||||
* as correct as the hardware can make them where n depends
|
||||
* on the display. This routine does not require wind to
|
||||
* be defined.
|
||||
*/
|
||||
unsigned long Resolve_Color(w, name)
|
||||
Window w;
|
||||
char *name;
|
||||
{
|
||||
XColor c;
|
||||
Colormap colormap;
|
||||
XWindowAttributes wind_info;
|
||||
|
||||
/*
|
||||
* The following is a hack to insure machines without a rgb table
|
||||
* handle at least white & black right.
|
||||
*/
|
||||
if (!strcmp(name, "white"))
|
||||
name="#ffffffffffff";
|
||||
if (!strcmp(name, "black"))
|
||||
name="#000000000000";
|
||||
|
||||
XGetWindowAttributes(dpy, w, &wind_info);
|
||||
colormap = wind_info.colormap;
|
||||
|
||||
if (!XParseColor(dpy, colormap, name, &c))
|
||||
Fatal_Error("Bad color format '%s'.", name);
|
||||
|
||||
if (!XAllocColor(dpy, colormap, &c))
|
||||
Fatal_Error("XAllocColor failed!");
|
||||
|
||||
return(c.pixel);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bitmap_To_Pixmap: Convert a bitmap to a 2 colored pixmap. The colors come
|
||||
* from the foreground and background colors of the gc.
|
||||
* Width and height are required solely for efficiency.
|
||||
* If needed, they can be obtained via. XGetGeometry.
|
||||
*/
|
||||
Pixmap Bitmap_To_Pixmap(dpy, d, gc, bitmap, width, height)
|
||||
Display *dpy;
|
||||
Drawable d;
|
||||
GC gc;
|
||||
Pixmap bitmap;
|
||||
int width, height;
|
||||
{
|
||||
Pixmap pix;
|
||||
int x;
|
||||
unsigned int i, depth;
|
||||
Drawable root;
|
||||
|
||||
if (!XGetGeometry(dpy, d, &root, &x, &x, &i, &i, &i, &depth))
|
||||
return(0);
|
||||
|
||||
pix = XCreatePixmap(dpy, d, width, height, (int)depth);
|
||||
|
||||
XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, 1);
|
||||
|
||||
return(pix);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* blip: a debugging routine. Prints Blip! on stderr with flushing.
|
||||
*/
|
||||
void blip()
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "blip!\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Routine to let user select a window using the mouse
|
||||
*/
|
||||
|
||||
Window Select_Window(dpy)
|
||||
Display *dpy;
|
||||
{
|
||||
int status;
|
||||
Cursor cursor;
|
||||
XEvent event;
|
||||
Window target_win = None, root = RootWindow(dpy,screen);
|
||||
int buttons = 0;
|
||||
|
||||
/* Make the target cursor */
|
||||
cursor = XCreateFontCursor(dpy, XC_crosshair);
|
||||
|
||||
/* Grab the pointer using target cursor, letting it room all over */
|
||||
status = XGrabPointer(dpy, root, False,
|
||||
ButtonPressMask|ButtonReleaseMask, GrabModeSync,
|
||||
GrabModeAsync, root, cursor, CurrentTime);
|
||||
if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
|
||||
|
||||
/* Let the user select a window... */
|
||||
while ((target_win == None) || (buttons != 0)) {
|
||||
/* allow one more event */
|
||||
XAllowEvents(dpy, SyncPointer, CurrentTime);
|
||||
XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
|
||||
switch (event.type) {
|
||||
case ButtonPress:
|
||||
if (target_win == None) {
|
||||
target_win = event.xbutton.subwindow; /* window selected */
|
||||
if (target_win == None) target_win = root;
|
||||
}
|
||||
buttons++;
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (buttons > 0) /* there may have been some down before we started */
|
||||
buttons--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
|
||||
|
||||
return(target_win);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Window_With_Name: routine to locate a window with a given name on a display.
|
||||
* If no window with the given name is found, 0 is returned.
|
||||
* If more than one window has the given name, the first
|
||||
* one found will be returned. Only top and its subwindows
|
||||
* are looked at. Normally, top should be the RootWindow.
|
||||
*/
|
||||
Window Window_With_Name(dpy, top, name)
|
||||
Display *dpy;
|
||||
Window top;
|
||||
char *name;
|
||||
{
|
||||
Window *children, dummy;
|
||||
unsigned int nchildren;
|
||||
int i;
|
||||
Window w=0;
|
||||
char *window_name;
|
||||
|
||||
if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
|
||||
return(top);
|
||||
|
||||
if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
|
||||
return(0);
|
||||
|
||||
for (i=0; i<nchildren; i++) {
|
||||
w = Window_With_Name(dpy, children[i], name);
|
||||
if (w)
|
||||
break;
|
||||
}
|
||||
if (children) XFree ((char *)children);
|
||||
return(w);
|
||||
}
|
||||
|
||||
/*
|
||||
* outl: a debugging routine. Flushes stdout then prints a message on stderr
|
||||
* and flushes stderr. Used to print messages when past certain points
|
||||
* in code so we can tell where we are. Outl may be invoked like
|
||||
* printf with up to 7 arguments.
|
||||
*/
|
||||
void
|
||||
outl(char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
fflush(stdout);
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Standard fatal error routine - call like printf but maximum of 7 arguments.
|
||||
* Does not require dpy or screen defined.
|
||||
*/
|
||||
void Fatal_Error(char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
fprintf(stderr, "%s: error: ", program_name);
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
108
tools/xprop/dsimple.h
Normal file
108
tools/xprop/dsimple.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
/* $Xorg: dsimple.h,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
|
||||
/*
|
||||
|
||||
Copyright 1993, 1998 The Open Group
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided that
|
||||
the above copyright notice appear in all copies and that both that
|
||||
copyright notice and this permission notice appear in supporting
|
||||
documentation.
|
||||
|
||||
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 OPEN GROUP 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.
|
||||
|
||||
Except as contained in this notice, the name of The Open Group shall
|
||||
not be used in advertising or otherwise to promote the sale, use or
|
||||
other dealings in this Software without prior written authorization
|
||||
from The Open Group.
|
||||
|
||||
*/
|
||||
/* $XFree86: xc/programs/xlsfonts/dsimple.h,v 1.7 2001/12/14 20:02:10 dawes Exp $ */
|
||||
|
||||
/*
|
||||
* Just_display.h: This file contains the definitions needed to use the
|
||||
* functions in just_display.c. It also declares the global
|
||||
* variables dpy, screen, and program_name which are needed to
|
||||
* use just_display.c.
|
||||
*
|
||||
* Written by Mark Lillibridge. Last updated 7/1/87
|
||||
*
|
||||
* Send bugs, etc. to chariot@athena.mit.edu.
|
||||
*/
|
||||
|
||||
/* Global variables used by routines in just_display.c */
|
||||
|
||||
extern char *program_name; /* Name of this program */
|
||||
extern Display *dpy; /* The current display */
|
||||
extern int screen; /* The current screen */
|
||||
|
||||
#define INIT_NAME program_name=argv[0] /* use this in main to setup
|
||||
program_name */
|
||||
|
||||
/* Declaritions for functions in just_display.c */
|
||||
|
||||
#if NeedFunctionPrototypes
|
||||
char *Malloc(unsigned);
|
||||
char *Realloc(char *, int);
|
||||
char *Get_Display_Name(int *, char **);
|
||||
Display *Open_Display(char *);
|
||||
void Setup_Display_And_Screen(int *, char **);
|
||||
XFontStruct *Open_Font(char *);
|
||||
void Beep(void);
|
||||
Pixmap ReadBitmapFile(Drawable, char *, int *, int *, int *, int *);
|
||||
void WriteBitmapFile(char *, Pixmap, int, int, int, int);
|
||||
Window Select_Window_Args(int *, char **);
|
||||
void usage(void);
|
||||
#else
|
||||
char *Malloc();
|
||||
char *Realloc();
|
||||
char *Get_Display_Name();
|
||||
Display *Open_Display();
|
||||
void Setup_Display_And_Screen();
|
||||
XFontStruct *Open_Font();
|
||||
void Beep();
|
||||
Pixmap ReadBitmapFile();
|
||||
void WriteBitmapFile();
|
||||
Window Select_Window_Args();
|
||||
void usage();
|
||||
#endif
|
||||
|
||||
#define X_USAGE "[host:display]" /* X arguments handled by
|
||||
Get_Display_Name */
|
||||
|
||||
/*
|
||||
* Other_stuff.h: Definitions of routines in other_stuff.
|
||||
*
|
||||
* Written by Mark Lillibridge. Last updated 7/1/87
|
||||
*
|
||||
* Send bugs, etc. to chariot@athena.mit.edu.
|
||||
*/
|
||||
|
||||
#if NeedFunctionPrototypes
|
||||
unsigned long Resolve_Color(Window, char *);
|
||||
Pixmap Bitmap_To_Pixmap(Display *, Drawable, GC, Pixmap, int, int);
|
||||
Window Select_Window(Display *);
|
||||
void blip(void);
|
||||
Window Window_With_Name(Display *, Window, char *);
|
||||
#else
|
||||
unsigned long Resolve_Color();
|
||||
Pixmap Bitmap_To_Pixmap();
|
||||
Window Select_Window();
|
||||
void blip();
|
||||
Window Window_With_Name();
|
||||
#endif
|
||||
#if __GNUC__
|
||||
void Fatal_Error(char *, ...) __attribute__((__noreturn__));
|
||||
#else
|
||||
void Fatal_Error(char *, ...);
|
||||
#endif
|
||||
void outl(char *, ...);
|
1723
tools/xprop/xprop.c
Normal file
1723
tools/xprop/xprop.c
Normal file
File diff suppressed because it is too large
Load diff
26
tools/xprop/xprop.c.patch
Normal file
26
tools/xprop/xprop.c.patch
Normal file
|
@ -0,0 +1,26 @@
|
|||
--- /home/seli/build/xc.42/programs/xprop/xprop.c 2002-01-19 10:47:59.000000000 +0100
|
||||
+++ xprop.c 2002-12-21 11:52:06.000000000 +0100
|
||||
@@ -393,19 +393,19 @@ typedef struct _propertyRec {
|
||||
static propertyRec windowPropTable[] = {
|
||||
{"ARC", XA_ARC, "16iiccii", ARC_DFORMAT },
|
||||
{"ATOM", XA_ATOM, "32a", 0 },
|
||||
- {"BITMAP", XA_BITMAP, "32x", ": bitmap id # $0\n" },
|
||||
+ {"BITMAP", XA_BITMAP, "32x", ": bitmap id # $0+\n" },
|
||||
{"CARDINAL", XA_CARDINAL, "0c", 0 },
|
||||
{"COLORMAP", XA_COLORMAP, "32x", ": colormap id # $0\n" },
|
||||
{"CURSOR", XA_CURSOR, "32x", ": cursor id # $0\n" },
|
||||
- {"DRAWABLE", XA_DRAWABLE, "32x", ": drawable id # $0\n" },
|
||||
+ {"DRAWABLE", XA_DRAWABLE, "32x", ": drawable id # $0+\n" },
|
||||
{"FONT", XA_FONT, "32x", ": font id # $0\n" },
|
||||
{"INTEGER", XA_INTEGER, "0i", 0 },
|
||||
- {"PIXMAP", XA_PIXMAP, "32x", ": pixmap id # $0\n" },
|
||||
+ {"PIXMAP", XA_PIXMAP, "32x", ": pixmap id # $0+\n" },
|
||||
{"POINT", XA_POINT, "16ii", " = $0, $1\n" },
|
||||
{"RECTANGLE", XA_RECTANGLE, "16iicc", RECTANGLE_DFORMAT },
|
||||
{"RGB_COLOR_MAP", XA_RGB_COLOR_MAP,"32xcccccccxx",RGB_COLOR_MAP_DFORMAT},
|
||||
{"STRING", XA_STRING, "8s", 0 },
|
||||
- {"WINDOW", XA_WINDOW, "32x", ": window id # $0\n" },
|
||||
+ {"WINDOW", XA_WINDOW, "32x", ": window id # $0+\n" },
|
||||
{"VISUALID", XA_VISUALID, "32x", ": visual id # $0\n" },
|
||||
{"WM_COLORMAP_WINDOWS", 0, "32x", ": window id # $0+\n"},
|
||||
{"WM_COMMAND", XA_WM_COMMAND, "8s", " = { $0+ }\n" },
|
2
tools/xreply/Makefile
Normal file
2
tools/xreply/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
gcc -O2 -Wall -shared -fPIC -o libxreply.so xreply.c
|
197
tools/xreply/xreply.c
Normal file
197
tools/xreply/xreply.c
Normal file
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
|
||||
LD_PRELOAD library that gives statistic on number of roundtrips in an application.
|
||||
|
||||
$XREPLY_BACKTRACE defines whether and how backtraces will be printed for every
|
||||
roundtrip. If not set, only total number of roundtrips is printed after the process
|
||||
exits. If set to a number, backtrace for every roundtrip will be printed, and the
|
||||
backtraces will be as deep as the given number. If set to C<number> (e.g. C10),
|
||||
the backtraces will be "compressed" - every backtrace will be printed only once
|
||||
after the process exits, together with number of times it occured.
|
||||
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <execinfo.h>
|
||||
#include <assert.h>
|
||||
#include <X11/Xlibint.h>
|
||||
|
||||
/* Since these symbols are weak, the apps can provide their own, and therefore
|
||||
e.g. temporarily suspend counting of roundtrips. At least theoretically,
|
||||
I haven't really tried it.
|
||||
*/
|
||||
__attribute((weak)) long ___xreply_reply_count = 0;
|
||||
__attribute((weak)) int ___xreply_reply_enabled = 1;
|
||||
|
||||
#define MAX_BACKTRACES 1024
|
||||
|
||||
extern long ___xreply_reply_count;
|
||||
extern int ___xreply_reply_enabled;
|
||||
|
||||
typedef Status (*xreply_ptr_t)(Display*,xReply*,int,Bool);
|
||||
|
||||
static xreply_ptr_t xreply_ptr = NULL;
|
||||
static int xreply_backtrace_set = 0;
|
||||
static int xreply_backtrace_type = 0;
|
||||
|
||||
struct xreply_struct
|
||||
{
|
||||
char* key;
|
||||
char* text;
|
||||
int count;
|
||||
};
|
||||
static struct xreply_struct backtraces[ MAX_BACKTRACES ];
|
||||
static int backtraces_size = 0;
|
||||
|
||||
static int xreply_compare( const void* left, const void* right )
|
||||
{
|
||||
int left_count = ((struct xreply_struct*)left)->count;
|
||||
int right_count = ((struct xreply_struct*)right)->count;
|
||||
return right_count - left_count;
|
||||
}
|
||||
|
||||
static void xreply_print(void)
|
||||
{
|
||||
char tmp[ 1024 ];
|
||||
int fd;
|
||||
fd = open( "/proc/self/cmdline", O_RDONLY );
|
||||
if( fd >= 0 )
|
||||
{
|
||||
read( fd, tmp, 1024 );
|
||||
tmp[ 1023 ] = '\0';
|
||||
close( fd );
|
||||
}
|
||||
fprintf( stderr, "XREPLY (%d : %s): %ld\n", getpid(), tmp, ___xreply_reply_count );
|
||||
if( xreply_backtrace_type < 0 )
|
||||
{
|
||||
int i;
|
||||
qsort( backtraces, backtraces_size, sizeof( struct xreply_struct ), xreply_compare );
|
||||
for( i = 0;
|
||||
i < backtraces_size;
|
||||
++i )
|
||||
fprintf( stderr, "%d:%s\n\n", backtraces[ i ].count, backtraces[ i ].text );
|
||||
}
|
||||
}
|
||||
|
||||
static void xreply_backtrace()
|
||||
{
|
||||
void* trace[256];
|
||||
int n = backtrace(trace, 256);
|
||||
char** strings = backtrace_symbols (trace, n);
|
||||
|
||||
if( xreply_backtrace_type > 0 )
|
||||
{
|
||||
fprintf( stderr, "%ld [\n", ___xreply_reply_count );
|
||||
if( n > xreply_backtrace_type )
|
||||
n = xreply_backtrace_type;
|
||||
int i;
|
||||
for( i = 0;
|
||||
i < n;
|
||||
++i )
|
||||
fprintf( stderr, "%d: %s\n", i, strings[ i ] );
|
||||
fprintf( stderr, "]\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
char stack[ 256 * 20 ];
|
||||
int pos = 0;
|
||||
int i;
|
||||
stack[ 0 ] = '\0';
|
||||
if( n > -xreply_backtrace_type )
|
||||
n = -xreply_backtrace_type;
|
||||
for( i = 0;
|
||||
i < n;
|
||||
++i )
|
||||
{
|
||||
const char* start = strrchr( strings[ i ], '[' );
|
||||
if( start == NULL )
|
||||
assert( !"No [ in address." );
|
||||
long addr;
|
||||
if( sscanf( start + 1, "0x%lx", &addr ) != 1 )
|
||||
assert( !"Failed to parse address." );
|
||||
if( sizeof( void* ) == 4 )
|
||||
{
|
||||
sprintf( stack + pos, "0x%8lx", addr );
|
||||
pos += 10;
|
||||
}
|
||||
else if( sizeof( void* ) == 8 )
|
||||
{
|
||||
sprintf( stack + pos, "0x%16lx", addr );
|
||||
pos += 18;
|
||||
}
|
||||
else
|
||||
assert( !"Unknown sizeof( void* )." );
|
||||
}
|
||||
for( i = 0;
|
||||
i < backtraces_size;
|
||||
++i )
|
||||
if( strcmp( backtraces[ i ].key, stack ) == 0 )
|
||||
{
|
||||
++backtraces[ i ].count;
|
||||
break;
|
||||
}
|
||||
if( i == backtraces_size )
|
||||
{
|
||||
int stack_text_size = 10;
|
||||
char* stack_text;
|
||||
char* stack_text_pos;
|
||||
for( i = 0;
|
||||
i < n;
|
||||
++i )
|
||||
stack_text_size += strlen( strings[ i ] ) + 5;
|
||||
stack_text = stack_text_pos = malloc( stack_text_size );
|
||||
for( i = 0;
|
||||
i < n;
|
||||
++i )
|
||||
{
|
||||
stack_text_pos = stpcpy( stack_text_pos, "\n" );
|
||||
stack_text_pos = stpcpy( stack_text_pos, strings[ i ] );
|
||||
}
|
||||
backtraces[ backtraces_size ].key = strdup( stack );
|
||||
backtraces[ backtraces_size ].text = stack_text;
|
||||
backtraces[ backtraces_size ].count = 1;
|
||||
++backtraces_size;
|
||||
if( backtraces_size >= MAX_BACKTRACES )
|
||||
assert( !"MAX_BACKTRACES reached." );
|
||||
}
|
||||
}
|
||||
free (strings);
|
||||
}
|
||||
|
||||
Status
|
||||
_XReply (dpy, rep, extra, discard)
|
||||
register Display *dpy;
|
||||
register xReply *rep;
|
||||
int extra; /* number of 32-bit words expected after the reply */
|
||||
Bool discard; /* should I discard data following "extra" words? */
|
||||
{
|
||||
if( ___xreply_reply_enabled )
|
||||
++___xreply_reply_count;
|
||||
if( xreply_backtrace_set == 0 )
|
||||
{
|
||||
if( getenv( "XREPLY_BACKTRACE" ) != NULL )
|
||||
{ // C<number> - compress backtraces, saved as negative value in xreply_backtrace_type
|
||||
if( getenv( "XREPLY_BACKTRACE" )[ 0 ] == 'C' )
|
||||
xreply_backtrace_type = -atoi( getenv( "XREPLY_BACKTRACE" ) + 1 );
|
||||
else // <number> - print the backtrace every time
|
||||
xreply_backtrace_type = atoi( getenv( "XREPLY_BACKTRACE" ));
|
||||
}
|
||||
else
|
||||
xreply_backtrace_type = 0;
|
||||
}
|
||||
if( xreply_backtrace_type != 0 )
|
||||
xreply_backtrace();
|
||||
if( xreply_ptr == NULL )
|
||||
{
|
||||
xreply_ptr = (xreply_ptr_t)dlsym( RTLD_NEXT, "_XReply" );
|
||||
if( xreply_ptr == NULL )
|
||||
assert( !"dlsym() failed." );
|
||||
atexit( xreply_print );
|
||||
}
|
||||
return xreply_ptr( dpy, rep, extra, discard );
|
||||
}
|
Loading…
Reference in a new issue