home *** CD-ROM | disk | FTP | other *** search
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
-
- Permission to use, copy, modify and distribute without
- charge this software, documentation, images, etc. is grant-
- ed, provided that this copyright and the author's name is
- retained.
-
- A fee may be charged for this program ONLY to recover costs
- for distribution (i.e. media costs). No profit can be made
- on this program.
-
- The author assumes no responsibility for disasters (natural
- or otherwise) as a consequence of use of this software.
-
- Adam Stein (stein.wbst129@xerox.com)
- */
-
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xatom.h>
- #include "xtoolplaces.h"
-
- extern char *remote,hostname[];
- extern Atom wm_save_yourself,wm_client_machine;
- extern Display *display;
- extern FILE *fp;
-
- /*This function will check a list of protocols to see if the WM_SAVE_YOURSELF
- protocol is in the list
-
- Inputs: count - number of protocols in list
- protocols - protocol list
- Outputs: 1 if WM_SAVE_YOURSELF is found, 0 otherwise
- Locals: none
- Globals: wm_save_yourself - WM_SAVE_YOURSELF atom
- */
- is_save_yourself(protocols,count)
- register int count;
- register Atom *protocols;
- {
- for(;count;--count)
- if(protocols[count-1] == wm_save_yourself)
- return(1);
-
- return(0);
- }
-
- /*This function will determine if a window is acting as a console window. It
- does this by first checking the class of the window. Since there is no
- standard class for consoles, maybe this program will start one. The window
- is considered a console if it's class is XConsole. If the class isn't
- XConsole (which is most likely the case), functions are called to check
- for each console type that I could think of. This includes contool,
- Sun's shelltool & cmdtool, and xterm. Each (of course) has a different
- way of identifying when it's on console mode. To add other consoles, just
- add another function call here and the function to make the check. A 1
- is returned if the window is a console, 0 otherwise.
-
- Inputs: command_line - WM_COMMAND arguments in a single string
- window - ID of the window that we are going to check
- Outputs: console - indicates if a window is a console
- Locals: class_hints - window class
- console - indicates if a window is a console
- status - status of get call
- Globals: display - interface info to X display
- CONSOLE_CLASS - class name for console windows
- */
- is_console(window,command_line)
- register char *command_line;
- register Window window;
- {
- register int console = 0;
- register Status status;
- XClassHint class_hints;
-
- /*Get window class and check it against what a class for a console
- window should be*/
- status = XGetClassHint(display,window,&class_hints);
- if(status && !strcmp(class_hints.res_class,CONSOLE_CLASS))
- console = 1;
- XFree(class_hints.res_name);
- XFree(class_hints.res_class);
-
- /*If the class doesn't match, check for each type of console
- window possible*/
- if(!console)
- if(!(console = check_contool(window)))
- if(!(console = check_sun_tools(window)))
- console = check_xterm(window,command_line);
-
- return(console);
- }
-
- /*This function will check to see if a window is the contool window. Since
- contool is always a console, we only have to check the window name to see
- if the word 'Contool' is in the name. A 1 is returned if it is a contool
- window, 0 otherwise.
-
- Inputs: window - ID of the window that we are going to check
- Outputs: contool - flag indicating if window is contool window or not
- Locals: contool - flag indicating if window is contool window or not
- name - X window name
- Globals: display - interface info to X display
- CONTOOL_NAME - name of contool window
- */
- check_contool(window)
- register Window window;
- {
- register int contool = 0;
- register char *name;
- char *getname();
-
- /*Get the name of the window to compare it against the name contool
- gives it's window*/
- name = getname(window);
- if(name && strstr(name,CONTOOL_NAME)) {
- contool = 1;
- XFree(name);
- }
-
- return(contool);
- }
-
- /*This function will check to see if a window is either a shelltool or
- cmdtool in the console mode. Since the icon name is CONSOLE only when
- either is started up in console mode, we can check that. A 1 is returned
- if it is in console mode, 0 otherwise.
-
- Inputs: window - ID of the window that we are going to check
- Outputs: sun_tools - flag indicating if window is in console mode
- Locals: status - status of get call
- sun_tools - flag indicating if window is in console mode
- tp - window's text property
- Globals: display - interface info to X display
- SUN_TOOLS_ICON_NAME - icon name for {shell,cmd}tool in console mode
- */
- check_sun_tools(window)
- register Window window;
- {
- register int sun_tools = 0;
- register Status status;
- XTextProperty tp;
-
- /*Get window's icon name and check it against what Sun labels the icon
- of either shelltool or cmdtool in console mode*/
- status = XGetWMIconName(display,window,&tp);
- if(status && !strcmp(tp.value,SUN_TOOLS_ICON_NAME))
- sun_tools = 1;
-
- XFree(tp.value);
-
- return(sun_tools);
- }
-
- /*This function will check to see if a window is xterm in the console mode.
- The only way to determine if xterm is in console mode is to check the
- options to see if it was started with the -C option. A 1 is returned
- if it is in console mode, 0 otherwise.
-
- Inputs: command_line - WM_COMMAND arguments in a single string
- window - ID of the window that we are going to check
- Outputs: xterm - flag indicating if window is xterm in console mode
- Locals: xterm - flag indicating if window is xterm in console mode
- Globals: XTERM_OPTION - xterm option to put it into console mode
- */
- check_xterm(window,command_line)
- register char *command_line;
- register Window window;
- {
- register int xterm = 0;
-
- /*See if it's xterm*/
- if(is_xterm(window) == 1)
- /*If window is xterm, then check argument list for xterm console
- mode option*/
- if(strstr(command_line,XTERM_OPTION)) xterm = 1;
-
- return(xterm);
- }
-
- /*This function determines if a particular window is an xterm window. To
- see if a window is an xterm window, we check it's class. Xterm always sets
- it class to "XTerm". 1 is returned if it is an xterm window, 0 if it
- isn't, -1 if there is an error in getting the name of the window.
-
- Inputs: window - ID of the window that we are going to check
- Outputs: 1 if xterm, 0 if not xterm, -1 if error in getting name
- Locals: match - flag indicating if window is xterm window or not
- status - status of get call
- tp - window's text property
- Globals: display - interface info to X display
- */
- is_xterm(window)
- register Window window;
- {
- register int match;
- register Status status;
- XClassHint class_hints;
-
- /*Get window class to see if it's xterm*/
- status = XGetClassHint(display,window,&class_hints);
-
- if(status) {
- match = strcmp(class_hints.res_class,"XTerm");
- XFree(class_hints.res_name);
- XFree(class_hints.res_class);
-
- return((!match)?1:0);
- } else return(-1);
- }
-
-
- /*This function checks to see if an application is being executed remotely.
- If it is, it prints out the remote execution command (typically 'rsh -n') and
- the name of the remote machine to execute on.
-
- Inputs: window - ID of the window that we are going to check
- Outputs: none
- Locals: status - status of get call
- tp - window's text property
- Globals: display - interface info to X display
- fp - file pointer to write window information to
- hostname - name of host
- remote - command to use for remote applications
- wm_client_machine - WM_CLIENT_MACHINE atom
- */
- is_remote(window)
- register Window window;
- {
- register Status status;
- XTextProperty tp;
-
- status = XGetTextProperty(display,window,&tp,wm_client_machine);
-
- /*Check if WM_CLIENT_MACHINE exists and isn't the name of the
- machine we are currently executing on*/
- if(status && strcmp(tp.value,hostname))
- fprintf(fp,"%s %s ",remote,tp.value);
- }
-
- /*This function gets the name of an X window and returns it.
-
- Inputs: window - ID of the window that we are going to check
- Outputs: tp.value - name of X window
- Locals: status - status of get call
- tp - window's text property
- Globals: display - interface info to X display
- NULL - 0
- */
- char *getname(window)
- register Window window;
- {
- register Status status;
- XTextProperty tp;
-
- /*Get the name of the window*/
- status = XGetWMName(display,window,&tp);
-
- if(status) return((char *) tp.value);
- else return(NULL);
- }
-
-