mirror of
https://github.com/brl/mutter.git
synced 2025-06-13 16:59:30 +00:00
...
This commit is contained in:
34
src/Makefile.am
Normal file
34
src/Makefile.am
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
SUBDIRS=uislave
|
||||
|
||||
INCLUDES=@METACITY_CFLAGS@
|
||||
|
||||
metacity_SOURCES= \
|
||||
api.c \
|
||||
api.h \
|
||||
colors.c \
|
||||
colors.h \
|
||||
display.c \
|
||||
display.h \
|
||||
errors.c \
|
||||
errors.h \
|
||||
eventqueue.c \
|
||||
eventqueue.h \
|
||||
frame.c \
|
||||
frame.h \
|
||||
main.c \
|
||||
main.h \
|
||||
screen.c \
|
||||
screen.h \
|
||||
theme.c \
|
||||
theme.h \
|
||||
uislave.c \
|
||||
uislave.h \
|
||||
util.c \
|
||||
util.h \
|
||||
window.c \
|
||||
window.h
|
||||
|
||||
bin_PROGRAMS=metacity
|
||||
|
||||
metacity_LDADD= @METACITY_LIBS@
|
@ -25,7 +25,7 @@
|
||||
/* don't add any internal headers here; api.h is an installed/public
|
||||
* header. Only theme.h is also installed.
|
||||
*/
|
||||
#include <Xlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <pango/pangox.h>
|
||||
|
||||
PangoContext* meta_get_pango_context (Screen *xscreen,
|
||||
|
@ -63,7 +63,9 @@ meta_display_open (const char *name)
|
||||
GSList *screens;
|
||||
GSList *tmp;
|
||||
int i;
|
||||
|
||||
char *atom_names[] = { "_NET_WM_NAME" };
|
||||
Atom atoms[G_N_ELEMENTS(atom_names)];
|
||||
|
||||
meta_verbose ("Opening display '%s'\n", XDisplayName (name));
|
||||
|
||||
xdisplay = XOpenDisplay (name);
|
||||
@ -122,6 +124,10 @@ meta_display_open (const char *name)
|
||||
|
||||
display->server_grab_count = 0;
|
||||
|
||||
XInternAtoms (display->xdisplay, atom_names, G_N_ELEMENTS (atom_names),
|
||||
False, atoms);
|
||||
display->atom_net_wm_name = atoms[0];
|
||||
|
||||
/* Now manage all existing windows */
|
||||
tmp = display->screens;
|
||||
while (tmp != NULL)
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define META_DISPLAY_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <Xlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <pango/pangox.h>
|
||||
#include "eventqueue.h"
|
||||
|
||||
@ -37,6 +37,8 @@ struct _MetaDisplay
|
||||
char *name;
|
||||
Display *xdisplay;
|
||||
|
||||
Atom atom_net_wm_name;
|
||||
|
||||
/*< private-ish >*/
|
||||
MetaEventQueue *events;
|
||||
GSList *screens;
|
||||
|
@ -73,7 +73,7 @@ meta_error_trap_pop (MetaDisplay *display)
|
||||
display->error_traps = next;
|
||||
|
||||
g_free (et);
|
||||
|
||||
|
||||
if (result != Success)
|
||||
{
|
||||
gchar buf[64];
|
||||
|
@ -20,7 +20,7 @@
|
||||
* 02111-1307, USA. */
|
||||
|
||||
#include "eventqueue.h"
|
||||
#include <Xlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
static gboolean eq_prepare (GSource *source,
|
||||
gint *timeout);
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define META_EVENT_QUEUE_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <Xlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
typedef struct _MetaEventQueue MetaEventQueue;
|
||||
|
||||
|
144
src/frame.c
144
src/frame.c
@ -82,7 +82,7 @@ meta_window_ensure_frame (MetaWindow *window)
|
||||
|
||||
background_pixel = geom.background_pixel;
|
||||
|
||||
switch (window->win_gravity)
|
||||
switch (window->size_hints.win_gravity)
|
||||
{
|
||||
case NorthWestGravity:
|
||||
frame->rect.x = window->rect.x;
|
||||
@ -127,18 +127,20 @@ meta_window_ensure_frame (MetaWindow *window)
|
||||
break;
|
||||
}
|
||||
|
||||
meta_verbose ("Creating frame %d,%d %dx%d around window 0x%lx %d,%d %dx%d with child position inside frame %d,%d\n",
|
||||
meta_verbose ("Creating frame %d,%d %dx%d around window 0x%lx %d,%d %dx%d with child position inside frame %d,%d and gravity %d\n",
|
||||
frame->rect.x, frame->rect.y,
|
||||
frame->rect.width, frame->rect.height,
|
||||
window->xwindow,
|
||||
window->rect.x, window->rect.y,
|
||||
window->rect.width, window->rect.height,
|
||||
child_x, child_y);
|
||||
child_x, child_y,
|
||||
window->size_hints.win_gravity);
|
||||
|
||||
attrs.background_pixel = background_pixel;
|
||||
attrs.event_mask =
|
||||
StructureNotifyMask | ExposureMask |
|
||||
ButtonPressMask | ButtonReleaseMask;
|
||||
ButtonPressMask | ButtonReleaseMask |
|
||||
PointerMotionMask | PointerMotionHintMask;
|
||||
|
||||
frame->xwindow = XCreateWindow (window->display->xdisplay,
|
||||
window->screen->xroot,
|
||||
@ -152,6 +154,13 @@ meta_window_ensure_frame (MetaWindow *window)
|
||||
window->xvisual,
|
||||
CWBackPixel | CWEventMask,
|
||||
&attrs);
|
||||
|
||||
meta_verbose ("Frame is 0x%lx\n", frame->xwindow);
|
||||
|
||||
frame->action = META_FRAME_ACTION_NONE;
|
||||
frame->last_x = 0;
|
||||
frame->last_y = 0;
|
||||
frame->start_button = 0;
|
||||
|
||||
meta_display_register_x_window (window->display, &frame->xwindow, window);
|
||||
|
||||
@ -172,12 +181,13 @@ meta_window_ensure_frame (MetaWindow *window)
|
||||
child_y);
|
||||
meta_error_trap_pop (window->display);
|
||||
|
||||
/* Show windows */
|
||||
XMapWindow (window->display->xdisplay, frame->xwindow);
|
||||
XMapWindow (window->display->xdisplay, window->xwindow);
|
||||
|
||||
/* stick frame to the window */
|
||||
window->frame = frame;
|
||||
window->frame = frame;
|
||||
|
||||
if (window->iconic)
|
||||
meta_window_hide (window);
|
||||
else
|
||||
meta_window_show (window);
|
||||
|
||||
/* Ungrab server */
|
||||
meta_display_ungrab (window->display);
|
||||
@ -223,23 +233,60 @@ meta_window_destroy_frame (MetaWindow *window)
|
||||
g_free (frame);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
meta_frame_show (MetaFrame *frame)
|
||||
meta_frame_move (MetaFrame *frame,
|
||||
int root_x,
|
||||
int root_y)
|
||||
{
|
||||
XMapWindow (frame->window->display->xdisplay, frame->xwindow);
|
||||
frame->rect.x = root_x;
|
||||
frame->rect.y = root_y;
|
||||
|
||||
XMoveWindow (frame->window->display->xdisplay,
|
||||
frame->xwindow,
|
||||
root_x, root_y);
|
||||
}
|
||||
|
||||
void
|
||||
meta_frame_hide (MetaFrame *frame)
|
||||
static void
|
||||
frame_query_root_pointer (MetaFrame *frame,
|
||||
int *x, int *y)
|
||||
{
|
||||
XUnmapWindow (frame->window->display->xdisplay, frame->xwindow);
|
||||
Window root_return, child_return;
|
||||
int root_x_return, root_y_return;
|
||||
int win_x_return, win_y_return;
|
||||
unsigned int mask_return;
|
||||
|
||||
XQueryPointer (frame->window->display->xdisplay,
|
||||
frame->xwindow,
|
||||
&root_return,
|
||||
&child_return,
|
||||
&root_x_return,
|
||||
&root_y_return,
|
||||
&win_x_return,
|
||||
&win_y_return,
|
||||
&mask_return);
|
||||
|
||||
if (x)
|
||||
*x = root_x_return;
|
||||
if (y)
|
||||
*y = root_y_return;
|
||||
}
|
||||
|
||||
static MetaFrameControl
|
||||
frame_get_control (MetaFrame *frame,
|
||||
int x, int y)
|
||||
{
|
||||
MetaFrameInfo info;
|
||||
meta_frame_init_info (frame, &info);
|
||||
|
||||
return frame->window->screen->engine->get_control (&info,
|
||||
x, y,
|
||||
frame->theme_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_frame_event (MetaFrame *frame,
|
||||
XEvent *event)
|
||||
{
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case KeyPress:
|
||||
@ -247,10 +294,68 @@ meta_frame_event (MetaFrame *frame,
|
||||
case KeyRelease:
|
||||
break;
|
||||
case ButtonPress:
|
||||
if (frame->action == META_FRAME_ACTION_NONE)
|
||||
{
|
||||
MetaFrameControl control;
|
||||
control = frame_get_control (frame,
|
||||
event->xbutton.x,
|
||||
event->xbutton.y);
|
||||
|
||||
if (((control == META_FRAME_CONTROL_TITLE ||
|
||||
control == META_FRAME_CONTROL_NONE) &&
|
||||
event->xbutton.button == 1) ||
|
||||
event->xbutton.button == 2)
|
||||
{
|
||||
meta_verbose ("Begin move on %s\n",
|
||||
frame->window->desc);
|
||||
frame->action = META_FRAME_ACTION_MOVING;
|
||||
frame->last_x = event->xbutton.x_root;
|
||||
frame->last_y = event->xbutton.y_root;
|
||||
frame->start_button = event->xbutton.button;
|
||||
}
|
||||
else if (control == META_FRAME_CONTROL_DELETE &&
|
||||
event->xbutton.button == 1)
|
||||
{
|
||||
/* FIXME delete event */
|
||||
meta_verbose ("Close control clicked on %s\n",
|
||||
frame->window->desc);
|
||||
}
|
||||
else if (control == META_FRAME_CONTROL_RESIZE_SE &&
|
||||
event->xbutton.button == 1)
|
||||
{
|
||||
/* FIXME begin a resize */
|
||||
meta_verbose ("Resize control clicked on %s\n",
|
||||
frame->window->desc);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (event->xbutton.button == frame->start_button)
|
||||
{
|
||||
frame->action = META_FRAME_ACTION_NONE;
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
switch (frame->action)
|
||||
{
|
||||
case META_FRAME_ACTION_MOVING:
|
||||
{
|
||||
int x, y;
|
||||
int new_x, new_y;
|
||||
frame_query_root_pointer (frame, &x, &y);
|
||||
|
||||
new_x = frame->rect.x + (x - frame->last_x);
|
||||
new_y = frame->rect.y + (y - frame->last_y);
|
||||
frame->last_x = x;
|
||||
frame->last_y = y;
|
||||
|
||||
meta_frame_move (frame, new_x, new_y);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EnterNotify:
|
||||
break;
|
||||
@ -290,19 +395,16 @@ meta_frame_event (MetaFrame *frame,
|
||||
return TRUE;
|
||||
break;
|
||||
case UnmapNotify:
|
||||
frame->action = META_FRAME_ACTION_NONE;
|
||||
break;
|
||||
case MapNotify:
|
||||
frame->action = META_FRAME_ACTION_NONE;
|
||||
break;
|
||||
case MapRequest:
|
||||
break;
|
||||
case ReparentNotify:
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
frame->rect.x = event->xconfigure.x;
|
||||
frame->rect.y = event->xconfigure.y;
|
||||
frame->rect.width = event->xconfigure.width;
|
||||
frame->rect.height = event->xconfigure.height;
|
||||
return TRUE;
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
break;
|
||||
|
21
src/frame.h
21
src/frame.h
@ -24,6 +24,13 @@
|
||||
|
||||
#include "window.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
META_FRAME_ACTION_NONE,
|
||||
META_FRAME_ACTION_MOVING,
|
||||
META_FRAME_ACTION_RESIZING
|
||||
} MetaFrameAction;
|
||||
|
||||
struct _MetaFrame
|
||||
{
|
||||
/* window we frame */
|
||||
@ -32,19 +39,27 @@ struct _MetaFrame
|
||||
/* reparent window */
|
||||
Window xwindow;
|
||||
|
||||
/* This is trusted info from where we put the
|
||||
* frame, not the result of ConfigureNotify
|
||||
*/
|
||||
MetaRectangle rect;
|
||||
|
||||
gpointer theme_data;
|
||||
|
||||
MetaFrameAction action;
|
||||
/* reference point for drags */
|
||||
int last_x, last_y;
|
||||
int start_button;
|
||||
};
|
||||
|
||||
void meta_window_ensure_frame (MetaWindow *window);
|
||||
void meta_window_destroy_frame (MetaWindow *window);
|
||||
|
||||
void meta_frame_show (MetaFrame *frame);
|
||||
void meta_frame_hide (MetaFrame *frame);
|
||||
void meta_frame_move (MetaFrame *frame,
|
||||
int root_x,
|
||||
int root_y);
|
||||
|
||||
gboolean meta_frame_event (MetaFrame *frame,
|
||||
XEvent *event);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "window.h"
|
||||
#include "colors.h"
|
||||
|
||||
#include <cursorfont.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
|
||||
|
58
src/theme.c
58
src/theme.c
@ -28,6 +28,8 @@ struct _DefaultFrameData
|
||||
{
|
||||
PangoLayout *layout;
|
||||
GC text_gc;
|
||||
GC fg_gc;
|
||||
int title_height;
|
||||
};
|
||||
|
||||
static gpointer
|
||||
@ -47,10 +49,19 @@ default_acquire_frame (MetaFrameInfo *info)
|
||||
|
||||
color.red = color.green = color.blue = 0xffff;
|
||||
vals.foreground = meta_get_x_pixel (info->screen, &color);
|
||||
/* FIXME memory-inefficient, could use the same one for all frames
|
||||
* w/ the same root window
|
||||
*/
|
||||
d->text_gc = XCreateGC (info->display,
|
||||
RootWindowOfScreen (info->screen),
|
||||
GCForeground,
|
||||
&vals);
|
||||
d->fg_gc = XCreateGC (info->display,
|
||||
RootWindowOfScreen (info->screen),
|
||||
GCForeground,
|
||||
&vals);
|
||||
|
||||
d->title_height = 0;
|
||||
|
||||
return d;
|
||||
}
|
||||
@ -67,14 +78,15 @@ default_release_frame (MetaFrameInfo *info,
|
||||
g_object_unref (G_OBJECT (d->layout));
|
||||
|
||||
XFreeGC (info->display, d->text_gc);
|
||||
XFreeGC (info->display, d->fg_gc);
|
||||
|
||||
g_free (d);
|
||||
}
|
||||
|
||||
#define VERTICAL_TEXT_PAD 3
|
||||
#define LEFT_WIDTH 2
|
||||
#define RIGHT_WIDTH 2
|
||||
#define BOTTOM_HEIGHT 2
|
||||
#define LEFT_WIDTH 15
|
||||
#define RIGHT_WIDTH 15
|
||||
#define BOTTOM_HEIGHT 20
|
||||
void
|
||||
default_fill_frame_geometry (MetaFrameInfo *info,
|
||||
MetaFrameGeometry *geom,
|
||||
@ -93,7 +105,8 @@ default_fill_frame_geometry (MetaFrameInfo *info,
|
||||
|
||||
pango_layout_get_pixel_extents (d->layout, NULL, &rect);
|
||||
|
||||
geom->top_height = rect.height + VERTICAL_TEXT_PAD * 2;
|
||||
d->title_height = rect.height + VERTICAL_TEXT_PAD * 2;
|
||||
geom->top_height = d->title_height;
|
||||
|
||||
geom->left_width = LEFT_WIDTH;
|
||||
geom->right_width = RIGHT_WIDTH;
|
||||
@ -111,6 +124,7 @@ default_expose_frame (MetaFrameInfo *info,
|
||||
gpointer frame_data)
|
||||
{
|
||||
DefaultFrameData *d;
|
||||
int close_size;
|
||||
|
||||
d = frame_data;
|
||||
|
||||
@ -120,15 +134,49 @@ default_expose_frame (MetaFrameInfo *info,
|
||||
d->layout,
|
||||
LEFT_WIDTH,
|
||||
VERTICAL_TEXT_PAD);
|
||||
|
||||
close_size = d->title_height;
|
||||
|
||||
XDrawLine (info->display,
|
||||
info->frame,
|
||||
d->fg_gc,
|
||||
info->width - RIGHT_WIDTH - close_size,
|
||||
VERTICAL_TEXT_PAD,
|
||||
info->width - RIGHT_WIDTH,
|
||||
d->title_height - VERTICAL_TEXT_PAD);
|
||||
|
||||
XDrawLine (info->display,
|
||||
info->frame,
|
||||
d->fg_gc,
|
||||
info->width - RIGHT_WIDTH,
|
||||
VERTICAL_TEXT_PAD,
|
||||
info->width - RIGHT_WIDTH - close_size,
|
||||
d->title_height - VERTICAL_TEXT_PAD);
|
||||
}
|
||||
|
||||
#define RESIZE_EXTENDS 10
|
||||
MetaFrameControl
|
||||
default_get_control (MetaFrameInfo *info,
|
||||
int x, int y,
|
||||
gpointer frame_data)
|
||||
{
|
||||
DefaultFrameData *d;
|
||||
int close_size;
|
||||
|
||||
d = frame_data;
|
||||
|
||||
|
||||
close_size = d->title_height;
|
||||
if (y < d->title_height &&
|
||||
x > info->width - RIGHT_WIDTH - close_size)
|
||||
return META_FRAME_CONTROL_DELETE;
|
||||
|
||||
if (y < d->title_height)
|
||||
return META_FRAME_CONTROL_TITLE;
|
||||
|
||||
if (y > (info->height - BOTTOM_HEIGHT - RESIZE_EXTENDS) &&
|
||||
x > (info->width - RIGHT_WIDTH - RESIZE_EXTENDS))
|
||||
return META_FRAME_CONTROL_RESIZE_SE;
|
||||
|
||||
return META_FRAME_CONTROL_NONE;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
/* don't add any internal headers here; theme.h is an installed/public
|
||||
* header.
|
||||
*/
|
||||
#include <Xlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <glib.h>
|
||||
|
||||
typedef struct _MetaFrameInfo MetaFrameInfo;
|
||||
|
29
src/uislave.c
Normal file
29
src/uislave.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* Metacity UI Slave */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "uislave.h"
|
||||
|
||||
MetaUISlave*
|
||||
meta_ui_slave_new (const char *display_name)
|
||||
{
|
||||
|
||||
|
||||
}
|
39
src/uislave.h
Normal file
39
src/uislave.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* Metacity UI Slave */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef META_UI_SLAVE_H
|
||||
#define META_UI_SLAVE_H
|
||||
|
||||
#include "util.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
typedef struct _MetaUISlave MetaUISlave;
|
||||
|
||||
struct _MetaUISlave
|
||||
{
|
||||
char *display_name;
|
||||
};
|
||||
|
||||
MetaUISlave* meta_ui_slave_new (const char *display_name);
|
||||
|
||||
|
||||
#endif
|
9
src/uislave/Makefile.am
Normal file
9
src/uislave/Makefile.am
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
INCLUDES=@UISLAVE_CFLAGS@
|
||||
|
||||
metacity_uislave_SOURCES = \
|
||||
main.c
|
||||
|
||||
libexec_PROGRAMS=metacity-uislave
|
||||
|
||||
metacity_uislave_LDADD = @UISLAVE_LIBS@
|
27
src/uislave/main.c
Normal file
27
src/uislave/main.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* Metacity UI slave main() */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
405
src/window.c
405
src/window.c
@ -23,6 +23,23 @@
|
||||
#include "util.h"
|
||||
#include "frame.h"
|
||||
#include "errors.h"
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
static void constrain_size (MetaWindow *window,
|
||||
int width,
|
||||
int height,
|
||||
int *new_width,
|
||||
int *new_height);
|
||||
static int update_size_hints (MetaWindow *window);
|
||||
static int update_title (MetaWindow *window);
|
||||
static int update_protocols (MetaWindow *window);
|
||||
static gboolean process_configure_request (MetaWindow *window,
|
||||
XConfigureRequestEvent *event);
|
||||
static gboolean process_property_notify (MetaWindow *window,
|
||||
XPropertyEvent *event);
|
||||
|
||||
|
||||
|
||||
|
||||
MetaWindow*
|
||||
meta_window_new (MetaDisplay *display, Window xwindow)
|
||||
@ -30,12 +47,12 @@ meta_window_new (MetaDisplay *display, Window xwindow)
|
||||
MetaWindow *window;
|
||||
XWindowAttributes attrs;
|
||||
GSList *tmp;
|
||||
|
||||
|
||||
meta_verbose ("Attempting to manage 0x%lx\n", xwindow);
|
||||
|
||||
/* round trip */
|
||||
meta_error_trap_push (display);
|
||||
|
||||
|
||||
if (XGetWindowAttributes (display->xdisplay,
|
||||
xwindow, &attrs) == Success &&
|
||||
attrs.override_redirect)
|
||||
@ -88,15 +105,20 @@ meta_window_new (MetaDisplay *display, Window xwindow)
|
||||
window->rect.y = attrs.y;
|
||||
window->rect.width = attrs.width;
|
||||
window->rect.height = attrs.height;
|
||||
window->border_width = attrs.border_width;
|
||||
window->win_gravity = attrs.win_gravity;
|
||||
window->depth = attrs.depth;
|
||||
window->xvisual = attrs.visual;
|
||||
|
||||
window->title = g_strdup ("Foo foo foo foo");
|
||||
window->title = NULL;
|
||||
window->iconic = FALSE;
|
||||
|
||||
window->desc = g_strdup_printf ("0x%lx", window->xwindow);
|
||||
|
||||
meta_display_register_x_window (display, &window->xwindow, window);
|
||||
|
||||
update_size_hints (window);
|
||||
update_title (window);
|
||||
update_protocols (window);
|
||||
|
||||
window->frame = NULL;
|
||||
meta_window_ensure_frame (window);
|
||||
|
||||
@ -117,6 +139,26 @@ meta_window_free (MetaWindow *window)
|
||||
g_free (window);
|
||||
}
|
||||
|
||||
void
|
||||
meta_window_show (MetaWindow *window)
|
||||
{
|
||||
if (window->frame)
|
||||
XMapWindow (window->display->xdisplay, window->frame->xwindow);
|
||||
XMapWindow (window->display->xdisplay, window->xwindow);
|
||||
|
||||
window->iconic = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
meta_window_hide (MetaWindow *window)
|
||||
{
|
||||
if (window->frame)
|
||||
XUnmapWindow (window->display->xdisplay, window->frame->xwindow);
|
||||
XUnmapWindow (window->display->xdisplay, window->xwindow);
|
||||
|
||||
window->iconic = TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_window_event (MetaWindow *window,
|
||||
XEvent *event)
|
||||
@ -165,12 +207,11 @@ meta_window_event (MetaWindow *window,
|
||||
return TRUE;
|
||||
break;
|
||||
case UnmapNotify:
|
||||
if (window->frame)
|
||||
meta_frame_hide (window->frame);
|
||||
/* Window withdrawn */
|
||||
meta_window_free (window);
|
||||
return TRUE;
|
||||
break;
|
||||
case MapNotify:
|
||||
if (window->frame)
|
||||
meta_frame_show (window->frame);
|
||||
break;
|
||||
case MapRequest:
|
||||
break;
|
||||
@ -179,21 +220,15 @@ meta_window_event (MetaWindow *window,
|
||||
case ConfigureNotify:
|
||||
if (event->xconfigure.override_redirect)
|
||||
{
|
||||
/* Unmanage it */
|
||||
/* Unmanage it, override_redirect was toggled on?
|
||||
* Can this happen?
|
||||
*/
|
||||
meta_window_free (window);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
window->rect.x = event->xconfigure.x;
|
||||
window->rect.y = event->xconfigure.y;
|
||||
window->rect.width = event->xconfigure.width;
|
||||
window->rect.height = event->xconfigure.height;
|
||||
window->border_width = event->xconfigure.border_width;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
return process_configure_request (window, &event->xconfigurerequest);
|
||||
break;
|
||||
case GravityNotify:
|
||||
break;
|
||||
@ -204,6 +239,7 @@ meta_window_event (MetaWindow *window,
|
||||
case CirculateRequest:
|
||||
break;
|
||||
case PropertyNotify:
|
||||
return process_property_notify (window, &event->xproperty);
|
||||
break;
|
||||
case SelectionClear:
|
||||
break;
|
||||
@ -224,3 +260,334 @@ meta_window_event (MetaWindow *window,
|
||||
/* Didn't use this event */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
process_property_notify (MetaWindow *window,
|
||||
XPropertyEvent *event)
|
||||
{
|
||||
if (event->atom == XA_WM_NAME ||
|
||||
event->atom == window->display->atom_net_wm_name)
|
||||
{
|
||||
update_title (window);
|
||||
}
|
||||
else if (event->atom == XA_WM_NORMAL_HINTS)
|
||||
{
|
||||
update_size_hints (window);
|
||||
}
|
||||
else if (event->atom == XA_WM_PROTOCOLS)
|
||||
{
|
||||
update_protocols (window);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
process_configure_request (MetaWindow *window,
|
||||
XConfigureRequestEvent *event)
|
||||
{
|
||||
/* ICCCM 4.1.5 */
|
||||
|
||||
/* Note that x, y is the corner of the window border,
|
||||
* and width, height is the size of the window inside
|
||||
* its border, but that we always deny border requests
|
||||
* because we don't believe in clients who use lame-ass
|
||||
* X features like that.
|
||||
*/
|
||||
window->border_width = event->border_width;
|
||||
window->size_hints.x = event->x;
|
||||
window->size_hints.y = event->y;
|
||||
window->size_hints.width = event->width;
|
||||
window->size_hints.height = event->height;
|
||||
|
||||
/* FIXME */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
update_size_hints (MetaWindow *window)
|
||||
{
|
||||
int x, y, w, h;
|
||||
|
||||
/* Save the last ConfigureRequest, which we put here.
|
||||
* Values here set in the hints are supposed to
|
||||
* be ignored.
|
||||
*/
|
||||
x = window->size_hints.x;
|
||||
y = window->size_hints.y;
|
||||
w = window->size_hints.width;
|
||||
h = window->size_hints.height;
|
||||
|
||||
window->size_hints.flags = 0;
|
||||
|
||||
meta_error_trap_push (window->display);
|
||||
XGetNormalHints (window->display->xdisplay,
|
||||
window->xwindow,
|
||||
&window->size_hints);
|
||||
|
||||
/* Put it back. */
|
||||
window->size_hints.x = x;
|
||||
window->size_hints.y = y;
|
||||
window->size_hints.width = w;
|
||||
window->size_hints.height = h;
|
||||
|
||||
if (window->size_hints.flags & PBaseSize)
|
||||
;
|
||||
else if (window->size_hints.flags & PMinSize)
|
||||
{
|
||||
window->size_hints.base_width = window->size_hints.min_width;
|
||||
window->size_hints.base_height = window->size_hints.min_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
window->size_hints.base_width = 0;
|
||||
window->size_hints.base_height = 0;
|
||||
}
|
||||
window->size_hints.flags |= PBaseSize;
|
||||
|
||||
if (window->size_hints.flags & PMinSize)
|
||||
;
|
||||
else if (window->size_hints.flags & PBaseSize)
|
||||
{
|
||||
window->size_hints.min_width = window->size_hints.base_width;
|
||||
window->size_hints.min_height = window->size_hints.base_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
window->size_hints.min_width = 0;
|
||||
window->size_hints.min_height = 0;
|
||||
}
|
||||
window->size_hints.flags |= PMinSize;
|
||||
|
||||
if (window->size_hints.flags & PMaxSize)
|
||||
;
|
||||
else
|
||||
{
|
||||
window->size_hints.max_width = G_MAXINT;
|
||||
window->size_hints.max_height = G_MAXINT;
|
||||
window->size_hints.flags |= PMaxSize;
|
||||
}
|
||||
|
||||
if (window->size_hints.flags & PResizeInc)
|
||||
;
|
||||
else
|
||||
{
|
||||
window->size_hints.width_inc = 1;
|
||||
window->size_hints.height_inc = 1;
|
||||
window->size_hints.flags |= PResizeInc;
|
||||
}
|
||||
|
||||
if (window->size_hints.flags & PAspect)
|
||||
{
|
||||
/* don't divide by 0 */
|
||||
if (window->size_hints.min_aspect.y < 1)
|
||||
window->size_hints.min_aspect.y = 1;
|
||||
if (window->size_hints.max_aspect.y < 1)
|
||||
window->size_hints.max_aspect.y = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
window->size_hints.min_aspect.x = 1;
|
||||
window->size_hints.min_aspect.y = G_MAXINT;
|
||||
window->size_hints.max_aspect.x = G_MAXINT;
|
||||
window->size_hints.max_aspect.y = 1;
|
||||
window->size_hints.flags |= PAspect;
|
||||
}
|
||||
|
||||
if (window->size_hints.flags & PWinGravity)
|
||||
;
|
||||
else
|
||||
{
|
||||
window->size_hints.win_gravity = NorthWestGravity;
|
||||
window->size_hints.flags |= PWinGravity;
|
||||
}
|
||||
|
||||
/* FIXME constrain the window to these hints */
|
||||
|
||||
return meta_error_trap_pop (window->display);
|
||||
}
|
||||
|
||||
static int
|
||||
update_title (MetaWindow *window)
|
||||
{
|
||||
XTextProperty text;
|
||||
|
||||
meta_error_trap_push (window->display);
|
||||
|
||||
if (window->title)
|
||||
{
|
||||
g_free (window->title);
|
||||
window->title = NULL;
|
||||
}
|
||||
|
||||
/* FIXME How does memory management for text.value work? */
|
||||
XGetTextProperty (window->display->xdisplay,
|
||||
window->xwindow,
|
||||
&text,
|
||||
window->display->atom_net_wm_name);
|
||||
|
||||
if (text.nitems > 0 &&
|
||||
text.format == 8 &&
|
||||
g_utf8_validate (text.value, text.nitems, NULL))
|
||||
{
|
||||
meta_verbose ("Using _NET_WM_NAME for new title of %s: '%s'\n",
|
||||
window->desc, text.value);
|
||||
|
||||
window->title = g_strdup (text.value);
|
||||
}
|
||||
|
||||
if (window->title == NULL &&
|
||||
text.nitems > 0)
|
||||
meta_warning ("_NET_WM_NAME property for %s contained invalid UTF-8\n",
|
||||
window->desc);
|
||||
|
||||
if (window->title == NULL)
|
||||
{
|
||||
XGetTextProperty (window->display->xdisplay,
|
||||
window->xwindow,
|
||||
&text,
|
||||
XA_WM_NAME);
|
||||
|
||||
if (text.nitems > 0)
|
||||
{
|
||||
/* FIXME This isn't particularly correct. Need to copy the
|
||||
* GDK code...
|
||||
*/
|
||||
char *str;
|
||||
GError *err;
|
||||
|
||||
err = NULL;
|
||||
str = g_locale_to_utf8 (text.value,
|
||||
(text.format / 8) * text.nitems,
|
||||
NULL, NULL,
|
||||
&err);
|
||||
if (err != NULL)
|
||||
{
|
||||
meta_warning ("WM_NAME property for %s contained stuff we are too dumb to figure out: %s\n", window->desc, err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
if (window->title)
|
||||
meta_verbose ("Using WM_NAME for new title of %s: '%s'\n",
|
||||
window->desc, text.value);
|
||||
|
||||
window->title = str;
|
||||
}
|
||||
}
|
||||
|
||||
if (window->title == NULL)
|
||||
window->title = g_strdup ("");
|
||||
|
||||
window->desc = g_strdup_printf ("0x%lx (%.10s)", window->xwindow, window->title);
|
||||
|
||||
return meta_error_trap_pop (window->display);
|
||||
}
|
||||
|
||||
static int
|
||||
update_protocols (MetaWindow *window)
|
||||
{
|
||||
Atom *protocols;
|
||||
int n_protocols;
|
||||
int i;
|
||||
|
||||
meta_error_trap_push (window->display);
|
||||
XGetWMProtocols (window->display->xdisplay,
|
||||
window->xwindow,
|
||||
&protocols,
|
||||
&n_protocols);
|
||||
|
||||
window->take_focus = FALSE;
|
||||
window->delete_window = FALSE;
|
||||
i = 0;
|
||||
while (i < n_protocols)
|
||||
{
|
||||
if (protocols[i] == _XA_WM_TAKE_FOCUS)
|
||||
window->takes_focus = TRUE;
|
||||
else if (protocols[i] == _XA_WM_DELETE_WINDOW)
|
||||
window->delete_window = TRUE;
|
||||
++i;
|
||||
}
|
||||
|
||||
if (protocols)
|
||||
XFree (protocols);
|
||||
|
||||
return meta_error_trap_pop (window->display);
|
||||
}
|
||||
|
||||
static void
|
||||
constrain_size (MetaWindow *window,
|
||||
int width, int height,
|
||||
int *new_width, int *new_height)
|
||||
{
|
||||
/* This is partially borrowed from GTK (LGPL), which in turn
|
||||
* partially borrowed from fvwm,
|
||||
*
|
||||
* Copyright 1993, Robert Nation
|
||||
* You may use this code for any purpose, as long as the original
|
||||
* copyright remains in the source code and all documentation
|
||||
*
|
||||
* which in turn borrows parts of the algorithm from uwm
|
||||
*/
|
||||
int delta;
|
||||
double min_aspect, max_aspect;
|
||||
|
||||
#define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
|
||||
|
||||
/* clamp width and height to min and max values
|
||||
*/
|
||||
width = CLAMP (width,
|
||||
window->size_hints.min_width,
|
||||
window->size_hints.max_width);
|
||||
height = CLAMP (height,
|
||||
window->size_hints.min_height,
|
||||
window->size_hints.max_height);
|
||||
|
||||
/* shrink to base + N * inc
|
||||
*/
|
||||
width = window->size_hints.base_width +
|
||||
FLOOR (width - window->size_hints.base_width, window->size_hints.width_inc);
|
||||
height = window->size_hints.base_height +
|
||||
FLOOR (height - window->size_hints.base_height, window->size_hints.height_inc);
|
||||
|
||||
/* constrain aspect ratio, according to:
|
||||
*
|
||||
* width
|
||||
* min_aspect <= -------- <= max_aspect
|
||||
* height
|
||||
*/
|
||||
|
||||
min_aspect = window->size_hints.min_aspect.x / (double) window->size_hints.min_aspect.y;
|
||||
max_aspect = window->size_hints.max_aspect.x / (double) window->size_hints.max_aspect.y;
|
||||
|
||||
if (min_aspect * height > width)
|
||||
{
|
||||
delta = FLOOR (height - width * min_aspect, window->size_hints.height_inc);
|
||||
if (height - delta >= window->size_hints.min_height)
|
||||
height -= delta;
|
||||
else
|
||||
{
|
||||
delta = FLOOR (height * min_aspect - width, window->size_hints.width_inc);
|
||||
if (width + delta <= window->size_hints.max_width)
|
||||
width += delta;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_aspect * height < width)
|
||||
{
|
||||
delta = FLOOR (width - height * max_aspect, window->size_hints.width_inc);
|
||||
if (width - delta >= window->size_hints.min_width)
|
||||
width -= delta;
|
||||
else
|
||||
{
|
||||
delta = FLOOR (width / max_aspect - height, window->size_hints.height_inc);
|
||||
if (height + delta <= window->size_hints.max_height)
|
||||
height += delta;
|
||||
}
|
||||
}
|
||||
|
||||
#undef FLOOR
|
||||
|
||||
*new_width = width;
|
||||
*new_height = height;
|
||||
}
|
||||
|
21
src/window.h
21
src/window.h
@ -24,6 +24,7 @@
|
||||
|
||||
#include "screen.h"
|
||||
#include "util.h"
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
struct _MetaWindow
|
||||
{
|
||||
@ -32,19 +33,33 @@ struct _MetaWindow
|
||||
Window xwindow;
|
||||
/* may be NULL! not all windows get decorated */
|
||||
MetaFrame *frame;
|
||||
MetaRectangle rect;
|
||||
int border_width;
|
||||
int win_gravity;
|
||||
int depth;
|
||||
Visual *xvisual;
|
||||
char *desc; /* used in debug spew */
|
||||
char *title;
|
||||
|
||||
guint iconic : 1;
|
||||
guint take_focus : 1;
|
||||
guint delete_window : 1;
|
||||
|
||||
/* The size we set the window to last. */
|
||||
MetaRectangle rect;
|
||||
|
||||
/* Requested geometry */
|
||||
int border_width;
|
||||
/* x/y/w/h here get filled with ConfigureRequest values */
|
||||
XSizeHints size_hints;
|
||||
};
|
||||
|
||||
MetaWindow* meta_window_new (MetaDisplay *display,
|
||||
Window xwindow);
|
||||
void meta_window_free (MetaWindow *window);
|
||||
void meta_window_show (MetaWindow *window);
|
||||
void meta_window_hide (MetaWindow *window);
|
||||
|
||||
gboolean meta_window_event (MetaWindow *window,
|
||||
XEvent *event);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user