Blame clients/mwm/WmWsmLib/disp.c

Packit b099d7
/* $TOG: disp.c /main/6 1997/06/18 17:34:28 samborn $ */
Packit b099d7
/*
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 * 
Packit b099d7
 */
Packit b099d7
/*
Packit b099d7
 * HISTORY
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include "wsm_proto.h"
Packit b099d7
Packit b099d7
WSMDispInfo * GDispInfo = NULL;
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetDispInfo
Packit b099d7
 *	Description: Gets the display information structure associated with
Packit b099d7
 *                   the display passed into this function.
Packit b099d7
 *	Arguments: dpy - The Display to get the info for.
Packit b099d7
 *	Returns: a WSMDispInfo structure for the display passed.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMDispInfo *
Packit b099d7
_WSMGetDispInfo(Display *dpy)
Packit b099d7
{
Packit b099d7
    enum { XA_WSM_NAME_CONNECT, XA_WSM_NAME_EXTENSIONS, XA_WSM_NAME_CONFIG_FMT,
Packit b099d7
	   XA_WSM_NAME_GET_STATE, XA_WSM_NAME_SET_STATE, XA_WSM_NAME_REG_WINDOW,
Packit b099d7
	   XA_WSM_NAME_WM_GET_BACKGROUND_WINDOW,
Packit b099d7
	   XA_WSM_NAME_WM_SET_BACKGROUND_WINDOW, XA_WSM_NAME_WM_WINDOWS,
Packit b099d7
	   XA_WSM_NAME_WM_FOCUS, XA_WSM_NAME_WM_POINTER, XA_TARGETS,
Packit b099d7
	   XA_MULTIPLE, XA_TIMESTAMP, NUM_ATOMS };
Packit b099d7
    static char *atom_names[] = {
Packit b099d7
           WSM_NAME_CONNECT, WSM_NAME_EXTENSIONS, WSM_NAME_CONFIG_FMT,
Packit b099d7
	   WSM_NAME_GET_STATE, WSM_NAME_SET_STATE, WSM_NAME_REG_WINDOW,
Packit b099d7
	   WSM_NAME_WM_GET_BACKGROUND_WINDOW,
Packit b099d7
	   WSM_NAME_WM_SET_BACKGROUND_WINDOW, WSM_NAME_WM_WINDOWS,
Packit b099d7
	   WSM_NAME_WM_FOCUS, WSM_NAME_WM_POINTER, "TARGETS",
Packit b099d7
	   "MULTIPLE", "TIMESTAMP" };
Packit b099d7
Packit b099d7
    WSMDispInfo * disp_info;
Packit b099d7
    Atom atoms[XtNumber(atom_names)];
Packit b099d7
Packit b099d7
    if (GDispInfo == NULL) {
Packit b099d7
	disp_info = GDispInfo = (WSMDispInfo *) XtMalloc(sizeof(WSMDispInfo));
Packit b099d7
    }
Packit b099d7
    else {
Packit b099d7
	disp_info = GDispInfo;
Packit b099d7
Packit b099d7
	 while (True) {
Packit b099d7
	    if (disp_info->disp == dpy)
Packit b099d7
		return(disp_info);
Packit b099d7
Packit b099d7
	    if (disp_info->next == NULL)
Packit b099d7
		break;
Packit b099d7
Packit b099d7
	    disp_info = disp_info->next;
Packit b099d7
	}
Packit b099d7
Packit b099d7
	/*
Packit b099d7
	 * This display is not on the global list, add it.
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	disp_info->next = (WSMDispInfo *) XtMalloc(sizeof(WSMDispInfo));
Packit b099d7
	disp_info = disp_info->next;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    disp_info->disp = dpy;
Packit b099d7
    
Packit b099d7
    /*
Packit b099d7
     * These are our names.
Packit b099d7
     * 
Packit b099d7
     * ||| Should use XtConvertAndStore().
Packit b099d7
     */
Packit b099d7
Packit b099d7
    XInternAtoms(dpy, atom_names, XtNumber(atom_names), False, atoms);
Packit b099d7
Packit b099d7
    disp_info->connect = atoms[XA_WSM_NAME_CONNECT];
Packit b099d7
    disp_info->extensions = atoms[XA_WSM_NAME_EXTENSIONS];
Packit b099d7
    disp_info->config_fmt = atoms[XA_WSM_NAME_CONFIG_FMT];
Packit b099d7
    disp_info->get_state = atoms[XA_WSM_NAME_GET_STATE];
Packit b099d7
    disp_info->set_state = atoms[XA_WSM_NAME_SET_STATE];
Packit b099d7
    disp_info->reg_window = atoms[XA_WSM_NAME_REG_WINDOW];
Packit b099d7
Packit b099d7
    disp_info->get_background = atoms[XA_WSM_NAME_WM_GET_BACKGROUND_WINDOW];
Packit b099d7
    disp_info->set_background = atoms[XA_WSM_NAME_WM_SET_BACKGROUND_WINDOW];
Packit b099d7
Packit b099d7
    disp_info->wm_windows = atoms[XA_WSM_NAME_WM_WINDOWS];
Packit b099d7
    disp_info->wm_focus   = atoms[XA_WSM_NAME_WM_FOCUS];
Packit b099d7
    disp_info->wm_pointer = atoms[XA_WSM_NAME_WM_POINTER];
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * These global resources are unlikely to change.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    disp_info->targets = atoms[XA_TARGETS];
Packit b099d7
    disp_info->multiple = atoms[XA_MULTIPLE];
Packit b099d7
    disp_info->timestamp = atoms[XA_TIMESTAMP];
Packit b099d7
Packit b099d7
    disp_info->screen_info = NULL;
Packit b099d7
    disp_info->next = NULL;
Packit b099d7
Packit b099d7
    return(disp_info);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetScreenInfo
Packit b099d7
 *	Description: Gets the screen information structure associated with
Packit b099d7
 *                   the display and screen passed into this function.
Packit b099d7
 *	Arguments: dpy - The Display to get the info for.
Packit b099d7
 *                 screen_number - The screen number.
Packit b099d7
 *	Returns: a WSMScreenInfo structure for the display passed.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMScreenInfo *
Packit b099d7
_WSMGetScreenInfo(Display *dpy, int screen_number)
Packit b099d7
{
Packit b099d7
    WSMDispInfo * disp_info = _WSMGetDispInfo(dpy);
Packit b099d7
    WSMScreenInfo *screen_info;
Packit b099d7
    char temp[BUFSIZ];
Packit b099d7
Packit b099d7
    if (disp_info->screen_info == NULL) {
Packit b099d7
	/*
Packit b099d7
	 * Didn't find any screen info on this display, allocate it
Packit b099d7
	 * and then drop down to the code below that fills in the data.
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	screen_info = (WSMScreenInfo *) XtMalloc(sizeof(WSMScreenInfo));
Packit b099d7
	disp_info->screen_info = screen_info;
Packit b099d7
    }
Packit b099d7
    else {
Packit b099d7
	screen_info = disp_info->screen_info;
Packit b099d7
Packit b099d7
	/*
Packit b099d7
	 * Hunt through the screen info structs on this display until we
Packit b099d7
	 * find one that matches the screen num passed.  If we don't find
Packit b099d7
	 * one then allocate a new one, put it on the end of the list and
Packit b099d7
	 * drop into the code below that fills in the data.
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	while (True) {
Packit b099d7
	    if (screen_info->screen_num == screen_number)
Packit b099d7
		return(screen_info);
Packit b099d7
	    
Packit b099d7
	    if (screen_info->next == NULL)
Packit b099d7
		break;
Packit b099d7
	    
Packit b099d7
	    screen_info = screen_info->next;
Packit b099d7
	}
Packit b099d7
Packit b099d7
	/*
Packit b099d7
	 * This screen is not on the display's screen list, add it.
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	screen_info->next = (WSMScreenInfo *) XtMalloc(sizeof(WSMScreenInfo));
Packit b099d7
	screen_info = screen_info->next;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    screen_info->screen_num = screen_number;
Packit b099d7
Packit b099d7
    sprintf(temp, WM_SELECTION_FORMAT, screen_number);
Packit b099d7
    screen_info->wm_selection = XInternAtom(dpy, temp, False);
Packit b099d7
Packit b099d7
    sprintf(temp, WSM_SELECTION_FORMAT, screen_number);
Packit b099d7
    screen_info->wsm_selection = XInternAtom(dpy, temp, False);
Packit b099d7
Packit b099d7
    screen_info->next = NULL;
Packit b099d7
    screen_info->global.num_attrs = 0;
Packit b099d7
    screen_info->window.num_attrs = 0;
Packit b099d7
    screen_info->icon.num_attrs = 0;
Packit b099d7
    screen_info->request_callback = NULL;
Packit b099d7
    screen_info->request_data = NULL;
Packit b099d7
Packit b099d7
    return(screen_info);
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
Packit b099d7
Packit b099d7
Packit b099d7
/*	Function Name: _WSMClearConfigScreenInfo
Packit b099d7
 *	Description: Resets the screen information structure associated with
Packit b099d7
 *                   the display and screen passed into this function.
Packit b099d7
 *	Arguments: dpy - The Display to get the info for.
Packit b099d7
 *                 screen_number - The screen number.
Packit b099d7
 *	Returns:
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_WSMClearConfigScreenInfo(Display *dpy, int screen_number)
Packit b099d7
{
Packit b099d7
    WSMDispInfo * disp_info = _WSMGetDispInfo(dpy);
Packit b099d7
    WSMScreenInfo *screen_info;
Packit b099d7
Packit b099d7
    if (disp_info->screen_info != NULL)
Packit b099d7
      {
Packit b099d7
	screen_info = disp_info->screen_info;
Packit b099d7
Packit b099d7
	/*
Packit b099d7
	 * Hunt through the screen info structs on this display until we
Packit b099d7
	 * find one that matches the screen num passed. 
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	while (True) {
Packit b099d7
	  if (screen_info->screen_num == screen_number)
Packit b099d7
	    break;
Packit b099d7
	  
Packit b099d7
	  if (screen_info->next == NULL)
Packit b099d7
	    return;
Packit b099d7
	  
Packit b099d7
	  screen_info = screen_info->next;
Packit b099d7
	}
Packit b099d7
Packit b099d7
	if (screen_info->global.num_attrs != 0){
Packit b099d7
	  XtFree((XtPointer)screen_info->global.attr_list);
Packit b099d7
	  screen_info->global.num_attrs = 0;
Packit b099d7
	}
Packit b099d7
	
Packit b099d7
	if (screen_info->window.num_attrs != 0){
Packit b099d7
	  XtFree((XtPointer)screen_info->window.attr_list);
Packit b099d7
	  screen_info->window.num_attrs = 0;
Packit b099d7
	}
Packit b099d7
	
Packit b099d7
	if (screen_info->icon.num_attrs != 0){
Packit b099d7
	  XtFree((XtPointer)screen_info->icon.attr_list);
Packit b099d7
	  screen_info->icon.num_attrs = 0;
Packit b099d7
	}
Packit b099d7
      }
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetConfigFormat
Packit b099d7
 *	Description: Gets the Configuration format for the dpy, scr and
Packit b099d7
 *                   type specified.
Packit b099d7
 *	Arguments: dpy - The display.
Packit b099d7
 *                 screen_number - The screen number.
Packit b099d7
 *                 type - The type of format required.
Packit b099d7
 *	Returns: A pointer to the config format, or NULL if none was
Packit b099d7
 *               found.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMConfigFormatData *
Packit b099d7
_WSMGetConfigFormat(Display *dpy, int screen_number, WSMConfigFormatType type)
Packit b099d7
{
Packit b099d7
    WSMScreenInfo *screen_info = _WSMGetScreenInfo(dpy, screen_number);
Packit b099d7
Packit b099d7
    if (screen_info == NULL)
Packit b099d7
	return(NULL);
Packit b099d7
Packit b099d7
    switch(type) {
Packit b099d7
    case WSM_GLOBAL_FMT:
Packit b099d7
	return(&(screen_info->global));
Packit b099d7
    case WSM_WINDOW_FMT:
Packit b099d7
	return(&(screen_info->window));
Packit b099d7
    case WSM_ICON_FMT:
Packit b099d7
	return(&(screen_info->icon));
Packit b099d7
    default:
Packit b099d7
	break;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetSelectionAtom
Packit b099d7
 *	Description: Gets the Selection atom for the manager that we want to
Packit b099d7
 *                   send to.
Packit b099d7
 *	Arguments: dpy - The display.
Packit b099d7
 *                 screen_number - The screen number.
Packit b099d7
 *                 send_to - Whether to send this to the WM or WSM.
Packit b099d7
 *	Returns: A pointer to the config format, or NULL if none was
Packit b099d7
 *               found.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Atom
Packit b099d7
_WSMGetSelectionAtom(Display *dpy, int screen_num, WSMClientType send_to)
Packit b099d7
{
Packit b099d7
    WSMScreenInfo *screen_info = _WSMGetScreenInfo(dpy, screen_num);
Packit b099d7
Packit b099d7
    if (screen_info == NULL)
Packit b099d7
	return(None);
Packit b099d7
Packit b099d7
    switch(send_to) {
Packit b099d7
    case WSM_WORKSPACE_MANAGER:
Packit b099d7
	return(screen_info->wsm_selection);
Packit b099d7
    case WSM_WINDOW_MANAGER:
Packit b099d7
	return(screen_info->wm_selection);
Packit b099d7
    default:
Packit b099d7
	break;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(None);
Packit b099d7
}