mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 00:50:42 -05:00
...
This commit is contained in:
commit
287b6b15d3
402
src/display.c
Normal file
402
src/display.c
Normal file
@ -0,0 +1,402 @@
|
||||
/* Metacity X display handler */
|
||||
|
||||
/*
|
||||
* 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 "display.h"
|
||||
#include "util.h"
|
||||
#include "main.h"
|
||||
#include "screen.h"
|
||||
#include "window.h"
|
||||
|
||||
static GSList *all_displays = NULL;
|
||||
|
||||
static void meta_spew_event (MetaDisplay *display,
|
||||
XEvent *event);
|
||||
static void event_queue_callback (MetaEventQueue *queue,
|
||||
XEvent *event,
|
||||
gpointer data);
|
||||
|
||||
|
||||
static gint
|
||||
unsigned_long_equal (gconstpointer v1,
|
||||
gconstpointer v2)
|
||||
{
|
||||
return *((const gulong*) v1) == *((const gulong*) v2);
|
||||
}
|
||||
|
||||
static guint
|
||||
unsigned_long_hash (gconstpointer v)
|
||||
{
|
||||
gulong val = * (const gulong *) v;
|
||||
|
||||
/* I'm not sure this works so well. */
|
||||
#if G_SIZEOF_LONG > 4
|
||||
return (guint) (val ^ (val >> 32));
|
||||
#else
|
||||
return val;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
meta_display_open (const char *name)
|
||||
{
|
||||
MetaDisplay *display;
|
||||
Display *xdisplay;
|
||||
int i;
|
||||
|
||||
meta_verbose ("Opening display '%s'\n", XDisplayName (name));
|
||||
|
||||
xdisplay = XOpenDisplay (name);
|
||||
|
||||
if (xdisplay == NULL)
|
||||
{
|
||||
meta_warning (_("Failed to open X Window System display '%s'\n"),
|
||||
XDisplayName (name));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
display = g_new (MetaDisplay, 1);
|
||||
|
||||
display->name = g_strdup (XDisplayName (name));
|
||||
display->xdisplay = xdisplay;
|
||||
display->events = meta_event_queue_new (display->xdisplay,
|
||||
event_queue_callback,
|
||||
display);
|
||||
|
||||
display->window_ids = g_hash_table_new (unsigned_long_hash, unsigned_long_equal);
|
||||
|
||||
all_displays = g_slist_prepend (all_displays, display);
|
||||
|
||||
display->screens = NULL;
|
||||
i = 0;
|
||||
while (i < ScreenCount (xdisplay))
|
||||
{
|
||||
display->screens = g_slist_prepend (display->screens,
|
||||
meta_screen_new (display, i));
|
||||
++i;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
free_window (gpointer key, gpointer value, gpointer data)
|
||||
{
|
||||
MetaWindow *window;
|
||||
|
||||
window = value;
|
||||
|
||||
meta_window_free (window);
|
||||
}
|
||||
|
||||
void
|
||||
meta_display_close (MetaDisplay *display)
|
||||
{
|
||||
g_hash_table_foreach (display->window_ids,
|
||||
free_window,
|
||||
NULL);
|
||||
|
||||
g_hash_table_destroy (display->window_ids);
|
||||
|
||||
meta_event_queue_free (display->events);
|
||||
XCloseDisplay (display->xdisplay);
|
||||
g_free (display->name);
|
||||
|
||||
all_displays = g_slist_remove (all_displays, display);
|
||||
|
||||
g_free (display);
|
||||
|
||||
if (all_displays == NULL)
|
||||
{
|
||||
meta_verbose ("Last display closed, quitting\n");
|
||||
meta_quit (META_EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
MetaScreen*
|
||||
meta_display_screen_for_root (MetaDisplay *display,
|
||||
Window xroot)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
tmp = display->screens;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
MetaScreen *screen = tmp->data;
|
||||
|
||||
if (xroot == screen->xroot)
|
||||
return screen;
|
||||
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean dump_events = TRUE;
|
||||
|
||||
static void
|
||||
event_queue_callback (MetaEventQueue *queue,
|
||||
XEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
MetaWindow *window;
|
||||
MetaDisplay *display;
|
||||
|
||||
display = data;
|
||||
|
||||
if (dump_events)
|
||||
meta_spew_event (display, event);
|
||||
|
||||
window = meta_display_lookup_window (display, event->xany.window);
|
||||
|
||||
if (window)
|
||||
{
|
||||
if (meta_window_event (window, event))
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case KeyPress:
|
||||
break;
|
||||
case KeyRelease:
|
||||
break;
|
||||
case ButtonPress:
|
||||
break;
|
||||
case ButtonRelease:
|
||||
break;
|
||||
case MotionNotify:
|
||||
break;
|
||||
case EnterNotify:
|
||||
break;
|
||||
case LeaveNotify:
|
||||
break;
|
||||
case FocusIn:
|
||||
break;
|
||||
case FocusOut:
|
||||
break;
|
||||
case KeymapNotify:
|
||||
break;
|
||||
case Expose:
|
||||
break;
|
||||
case GraphicsExpose:
|
||||
break;
|
||||
case NoExpose:
|
||||
break;
|
||||
case VisibilityNotify:
|
||||
break;
|
||||
case CreateNotify:
|
||||
break;
|
||||
case DestroyNotify:
|
||||
break;
|
||||
case UnmapNotify:
|
||||
break;
|
||||
case MapNotify:
|
||||
break;
|
||||
case MapRequest:
|
||||
break;
|
||||
case ReparentNotify:
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
break;
|
||||
case GravityNotify:
|
||||
break;
|
||||
case ResizeRequest:
|
||||
break;
|
||||
case CirculateNotify:
|
||||
break;
|
||||
case CirculateRequest:
|
||||
break;
|
||||
case PropertyNotify:
|
||||
break;
|
||||
case SelectionClear:
|
||||
break;
|
||||
case SelectionRequest:
|
||||
break;
|
||||
case SelectionNotify:
|
||||
break;
|
||||
case ColormapNotify:
|
||||
break;
|
||||
case ClientMessage:
|
||||
break;
|
||||
case MappingNotify:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_spew_event (MetaDisplay *display,
|
||||
XEvent *event)
|
||||
{
|
||||
|
||||
const char *name = NULL;
|
||||
char *extra = NULL;
|
||||
char *winname;
|
||||
MetaScreen *screen;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case KeyPress:
|
||||
name = "KeyPress";
|
||||
break;
|
||||
case KeyRelease:
|
||||
name = "KeyRelease";
|
||||
break;
|
||||
case ButtonPress:
|
||||
name = "ButtonPress";
|
||||
break;
|
||||
case ButtonRelease:
|
||||
name = "ButtonRelease";
|
||||
break;
|
||||
case MotionNotify:
|
||||
name = "MotionNotify";
|
||||
break;
|
||||
case EnterNotify:
|
||||
name = "EnterNotify";
|
||||
break;
|
||||
case LeaveNotify:
|
||||
name = "LeaveNotify";
|
||||
break;
|
||||
case FocusIn:
|
||||
name = "FocusIn";
|
||||
break;
|
||||
case FocusOut:
|
||||
name = "FocusOut";
|
||||
break;
|
||||
case KeymapNotify:
|
||||
name = "KeymapNotify";
|
||||
break;
|
||||
case Expose:
|
||||
name = "Expose";
|
||||
break;
|
||||
case GraphicsExpose:
|
||||
name = "GraphicsExpose";
|
||||
break;
|
||||
case NoExpose:
|
||||
name = "NoExpose";
|
||||
break;
|
||||
case VisibilityNotify:
|
||||
name = "VisibilityNotify";
|
||||
break;
|
||||
case CreateNotify:
|
||||
name = "CreateNotify";
|
||||
break;
|
||||
case DestroyNotify:
|
||||
name = "DestroyNotify";
|
||||
break;
|
||||
case UnmapNotify:
|
||||
name = "UnmapNotify";
|
||||
break;
|
||||
case MapNotify:
|
||||
name = "MapNotify";
|
||||
break;
|
||||
case MapRequest:
|
||||
name = "MapRequest";
|
||||
break;
|
||||
case ReparentNotify:
|
||||
name = "ReparentNotify";
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
name = "ConfigureNotify";
|
||||
extra = g_strdup_printf ("x: %d y: %d w: %d h: %d above: 0x%lx",
|
||||
event->xconfigure.x,
|
||||
event->xconfigure.y,
|
||||
event->xconfigure.width,
|
||||
event->xconfigure.height,
|
||||
event->xconfigure.above);
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
name = "ConfigureRequest";
|
||||
break;
|
||||
case GravityNotify:
|
||||
name = "GravityNotify";
|
||||
break;
|
||||
case ResizeRequest:
|
||||
name = "ResizeRequest";
|
||||
break;
|
||||
case CirculateNotify:
|
||||
name = "CirculateNotify";
|
||||
break;
|
||||
case CirculateRequest:
|
||||
name = "CirculateRequest";
|
||||
break;
|
||||
case PropertyNotify:
|
||||
name = "PropertyNotify";
|
||||
break;
|
||||
case SelectionClear:
|
||||
name = "SelectionClear";
|
||||
break;
|
||||
case SelectionRequest:
|
||||
name = "SelectionRequest";
|
||||
break;
|
||||
case SelectionNotify:
|
||||
name = "SelectionNotify";
|
||||
break;
|
||||
case ColormapNotify:
|
||||
name = "ColormapNotify";
|
||||
break;
|
||||
case ClientMessage:
|
||||
name = "ClientMessage";
|
||||
break;
|
||||
case MappingNotify:
|
||||
name = "MappingNotify";
|
||||
break;
|
||||
default:
|
||||
name = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
screen = meta_display_screen_for_root (display, event->xany.window);
|
||||
|
||||
if (screen)
|
||||
winname = g_strdup_printf ("root %d", screen->number);
|
||||
else
|
||||
winname = g_strdup_printf ("0x%lx", event->xany.window);
|
||||
|
||||
meta_verbose ("%s on %s%s %s\n", name, winname,
|
||||
extra ? ":" : "", extra ? extra : "");
|
||||
|
||||
g_free (winname);
|
||||
|
||||
if (extra)
|
||||
g_free (extra);
|
||||
}
|
||||
|
||||
MetaWindow*
|
||||
meta_display_lookup_window (MetaDisplay *display,
|
||||
Window xwindow)
|
||||
{
|
||||
return g_hash_table_lookup (display->window_ids, &xwindow);
|
||||
}
|
||||
|
||||
void
|
||||
meta_display_register_window (MetaDisplay *display,
|
||||
MetaWindow *window)
|
||||
{
|
||||
g_return_if_fail (g_hash_table_lookup (display->window_ids, &window->xwindow) == NULL);
|
||||
|
||||
g_hash_table_insert (display->window_ids, &window->xwindow, window);
|
||||
}
|
56
src/display.h
Normal file
56
src/display.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* Metacity X display handler */
|
||||
|
||||
/*
|
||||
* 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_DISPLAY_H
|
||||
#define META_DISPLAY_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <Xlib.h>
|
||||
#include "eventqueue.h"
|
||||
|
||||
typedef struct _MetaWindow MetaWindow;
|
||||
typedef struct _MetaScreen MetaScreen;
|
||||
typedef struct _MetaDisplay MetaDisplay;
|
||||
|
||||
struct _MetaDisplay
|
||||
{
|
||||
char *name;
|
||||
Display *xdisplay;
|
||||
|
||||
/*< private >*/
|
||||
MetaEventQueue *events;
|
||||
GSList *screens;
|
||||
GHashTable *window_ids;
|
||||
};
|
||||
|
||||
gboolean meta_display_open (const char *name);
|
||||
void meta_display_close (MetaDisplay *display);
|
||||
MetaScreen* meta_display_screen_for_root (MetaDisplay *display,
|
||||
Window xroot);
|
||||
|
||||
MetaWindow* meta_display_lookup_window (MetaDisplay *display,
|
||||
Window xwindow);
|
||||
void meta_display_register_window (MetaDisplay *display,
|
||||
MetaWindow *window);
|
||||
|
||||
|
||||
|
||||
#endif
|
181
src/eventqueue.c
Normal file
181
src/eventqueue.c
Normal file
@ -0,0 +1,181 @@
|
||||
/* Metacity X event source for main loop */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington (based on GDK code (C) Owen
|
||||
* Taylor, Red Hat Inc.)
|
||||
*
|
||||
* 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 "eventqueue.h"
|
||||
#include <Xlib.h>
|
||||
|
||||
static gboolean eq_prepare (GSource *source,
|
||||
gint *timeout);
|
||||
static gboolean eq_check (GSource *source);
|
||||
static gboolean eq_dispatch (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data);
|
||||
static void eq_destroy (GSource *source);
|
||||
|
||||
static GSourceFuncs eq_funcs = {
|
||||
eq_prepare,
|
||||
eq_check,
|
||||
eq_dispatch,
|
||||
eq_destroy
|
||||
};
|
||||
|
||||
struct _MetaEventQueue
|
||||
{
|
||||
GSource source;
|
||||
|
||||
Display *display;
|
||||
GPollFD poll_fd;
|
||||
int connection_fd;
|
||||
GQueue *events;
|
||||
};
|
||||
|
||||
MetaEventQueue*
|
||||
meta_event_queue_new (Display *display, MetaEventQueueFunc func, gpointer data)
|
||||
{
|
||||
GSource *source;
|
||||
MetaEventQueue *eq;
|
||||
|
||||
source = g_source_new (&eq_funcs, sizeof (MetaEventQueue));
|
||||
eq = (MetaEventQueue*) source;
|
||||
|
||||
eq->connection_fd = ConnectionNumber (display);
|
||||
eq->poll_fd.fd = eq->connection_fd;
|
||||
eq->poll_fd.events = G_IO_IN;
|
||||
|
||||
eq->events = g_queue_new ();
|
||||
|
||||
eq->display = display;
|
||||
|
||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
||||
g_source_add_poll (source, &eq->poll_fd);
|
||||
g_source_set_can_recurse (source, TRUE);
|
||||
|
||||
g_source_set_callback (source, (GSourceFunc) func, data, NULL);
|
||||
|
||||
g_source_attach (source, NULL);
|
||||
|
||||
return eq;
|
||||
}
|
||||
|
||||
void
|
||||
meta_event_queue_free (MetaEventQueue *eq)
|
||||
{
|
||||
GSource *source;
|
||||
|
||||
source = (GSource*) eq;
|
||||
|
||||
g_source_destroy (source);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
eq_events_pending (MetaEventQueue *eq)
|
||||
{
|
||||
return eq->events->length > 0 || XPending (eq->display);
|
||||
}
|
||||
|
||||
static void
|
||||
eq_queue_events (MetaEventQueue *eq)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
while (XPending (eq->display))
|
||||
{
|
||||
XEvent *copy;
|
||||
|
||||
XNextEvent (eq->display, &xevent);
|
||||
|
||||
copy = g_new (XEvent, 1);
|
||||
*copy = xevent;
|
||||
|
||||
g_queue_push_tail (eq->events, copy);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
eq_prepare (GSource *source, gint *timeout)
|
||||
{
|
||||
MetaEventQueue *eq;
|
||||
|
||||
eq = (MetaEventQueue*) source;
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
return eq_events_pending (eq);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
eq_check (GSource *source)
|
||||
{
|
||||
MetaEventQueue *eq;
|
||||
|
||||
eq = (MetaEventQueue*) source;
|
||||
|
||||
if (eq->poll_fd.revents & G_IO_IN)
|
||||
return eq_events_pending (eq);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
eq_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
|
||||
{
|
||||
MetaEventQueue *eq;
|
||||
|
||||
eq = (MetaEventQueue*) source;
|
||||
|
||||
eq_queue_events (eq);
|
||||
|
||||
if (eq->events->length > 0)
|
||||
{
|
||||
XEvent *event;
|
||||
MetaEventQueueFunc func;
|
||||
|
||||
event = g_queue_pop_head (eq->events);
|
||||
func = (MetaEventQueueFunc) callback;
|
||||
|
||||
(* func) (eq, event, user_data);
|
||||
|
||||
g_free (event);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
eq_destroy (GSource *source)
|
||||
{
|
||||
MetaEventQueue *eq;
|
||||
|
||||
eq = (MetaEventQueue*) source;
|
||||
|
||||
while (eq->events->length > 0)
|
||||
{
|
||||
XEvent *event;
|
||||
|
||||
event = g_queue_pop_head (eq->events);
|
||||
|
||||
g_free (event);
|
||||
}
|
||||
|
||||
g_queue_free (eq->events);
|
||||
|
||||
/* source itself is freed by glib */
|
||||
}
|
39
src/eventqueue.h
Normal file
39
src/eventqueue.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* Metacity X event source for main loop */
|
||||
|
||||
/*
|
||||
* 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_EVENT_QUEUE_H
|
||||
#define META_EVENT_QUEUE_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <Xlib.h>
|
||||
|
||||
typedef struct _MetaEventQueue MetaEventQueue;
|
||||
|
||||
typedef void (* MetaEventQueueFunc) (MetaEventQueue *queue,
|
||||
XEvent *event,
|
||||
gpointer data);
|
||||
|
||||
MetaEventQueue* meta_event_queue_new (Display *display,
|
||||
MetaEventQueueFunc func,
|
||||
gpointer data);
|
||||
void meta_event_queue_free (MetaEventQueue *eq);
|
||||
|
||||
#endif
|
64
src/main.c
Normal file
64
src/main.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* Metacity 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.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
#include "display.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static MetaExitCode meta_exit_code = META_EXIT_SUCCESS;
|
||||
static GMainLoop *meta_main_loop = NULL;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
meta_main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
if (!meta_display_open (NULL))
|
||||
meta_exit (META_EXIT_ERROR);
|
||||
|
||||
g_main_run (meta_main_loop);
|
||||
|
||||
return meta_exit_code;
|
||||
}
|
||||
|
||||
GMainLoop*
|
||||
meta_get_main_loop (void)
|
||||
{
|
||||
return meta_main_loop;
|
||||
}
|
||||
|
||||
void
|
||||
meta_quit (MetaExitCode code)
|
||||
{
|
||||
meta_exit_code = code;
|
||||
|
||||
g_main_quit (meta_main_loop);
|
||||
}
|
||||
|
||||
void
|
||||
meta_exit (MetaExitCode code)
|
||||
{
|
||||
|
||||
exit (code);
|
||||
}
|
||||
|
41
src/main.h
Normal file
41
src/main.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* Metacity 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.
|
||||
*/
|
||||
|
||||
#ifndef META_MAIN_H
|
||||
#define META_MAIN_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
META_EXIT_SUCCESS,
|
||||
META_EXIT_ERROR
|
||||
} MetaExitCode;
|
||||
|
||||
/* exit immediately */
|
||||
void meta_exit (MetaExitCode code);
|
||||
|
||||
/* g_main_quit() then fall out of main() */
|
||||
void meta_quit (MetaExitCode code);
|
||||
|
||||
GMainLoop* meta_get_main_loop (void);
|
||||
|
||||
#endif
|
53
src/screen.c
Normal file
53
src/screen.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* Metacity X screen handler */
|
||||
|
||||
/*
|
||||
* 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 "screen.h"
|
||||
#include "util.h"
|
||||
|
||||
MetaScreen*
|
||||
meta_screen_new (MetaDisplay *display,
|
||||
int number)
|
||||
{
|
||||
MetaScreen *screen;
|
||||
|
||||
meta_verbose ("Adding screen %d on display '%s'\n", number, display->name);
|
||||
|
||||
screen = g_new (MetaScreen, 1);
|
||||
|
||||
screen->display = display;
|
||||
screen->number = number;
|
||||
screen->xscreen = ScreenOfDisplay (display->xdisplay, number);
|
||||
screen->xroot = RootWindow (display->xdisplay, number);
|
||||
|
||||
/* Select our root window events */
|
||||
XSelectInput (display->xdisplay,
|
||||
screen->xroot,
|
||||
SubstructureNotifyMask);
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
void
|
||||
meta_screen_free (MetaScreen *screen)
|
||||
{
|
||||
g_free (screen);
|
||||
}
|
||||
|
||||
|
39
src/screen.h
Normal file
39
src/screen.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* Metacity X screen handler */
|
||||
|
||||
/*
|
||||
* 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_SCREEN_H
|
||||
#define META_SCREEN_H
|
||||
|
||||
#include "display.h"
|
||||
|
||||
struct _MetaScreen
|
||||
{
|
||||
MetaDisplay *display;
|
||||
int number;
|
||||
Screen *xscreen;
|
||||
Window xroot;
|
||||
};
|
||||
|
||||
MetaScreen* meta_screen_new (MetaDisplay *display,
|
||||
int number);
|
||||
void meta_screen_free (MetaScreen *screen);
|
||||
|
||||
#endif
|
119
src/util.c
Normal file
119
src/util.c
Normal file
@ -0,0 +1,119 @@
|
||||
/* Metacity utilities */
|
||||
|
||||
/*
|
||||
* 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 "util.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static gboolean is_verbose = TRUE;
|
||||
|
||||
gboolean
|
||||
meta_is_verbose (void)
|
||||
{
|
||||
return is_verbose;
|
||||
}
|
||||
|
||||
void
|
||||
meta_set_verbose (gboolean setting)
|
||||
{
|
||||
is_verbose = setting;
|
||||
}
|
||||
|
||||
void
|
||||
meta_debug_spew (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
|
||||
g_return_if_fail (format != NULL);
|
||||
|
||||
if (!is_verbose)
|
||||
return;
|
||||
|
||||
va_start (args, format);
|
||||
str = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
fputs ("Window manager: ", stderr);
|
||||
fputs (str, stderr);
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
void
|
||||
meta_verbose (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
|
||||
g_return_if_fail (format != NULL);
|
||||
|
||||
if (!is_verbose)
|
||||
return;
|
||||
|
||||
va_start (args, format);
|
||||
str = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
fputs ("Window manager: ", stderr);
|
||||
fputs (str, stderr);
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
void
|
||||
meta_warning (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
|
||||
g_return_if_fail (format != NULL);
|
||||
|
||||
va_start (args, format);
|
||||
str = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
fputs ("Window manager: ", stderr);
|
||||
fputs (str, stderr);
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
void
|
||||
meta_fatal (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
|
||||
g_return_if_fail (format != NULL);
|
||||
|
||||
va_start (args, format);
|
||||
str = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
fputs ("Window manager: ", stderr);
|
||||
fputs (str, stderr);
|
||||
|
||||
g_free (str);
|
||||
|
||||
meta_exit (META_EXIT_ERROR);
|
||||
}
|
42
src/util.h
Normal file
42
src/util.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* Metacity utilities */
|
||||
|
||||
/*
|
||||
* 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_UTIL_H
|
||||
#define META_UTIL_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
gboolean meta_is_verbose (void);
|
||||
void meta_set_verbose (gboolean setting);
|
||||
|
||||
void meta_debug_spew (const char *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
void meta_verbose (const char *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
void meta_warning (const char *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
void meta_fatal (const char *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
|
||||
/* FIXME */
|
||||
#define _(x) x
|
||||
|
||||
#endif
|
77
src/window.c
Normal file
77
src/window.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* Metacity X managed windows */
|
||||
|
||||
/*
|
||||
* 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 "window.h"
|
||||
#include "util.h"
|
||||
|
||||
MetaWindow*
|
||||
meta_window_new (MetaDisplay *display, Window xwindow)
|
||||
{
|
||||
MetaWindow *window;
|
||||
XWindowAttributes attrs;
|
||||
GSList *tmp;
|
||||
|
||||
/* round trip */
|
||||
if (XGetWindowAttributes (display->xdisplay,
|
||||
xwindow, &attrs) != Success)
|
||||
{
|
||||
meta_verbose ("Window 0x%lx disappeared just as we tried to manage it\n",
|
||||
xwindow);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
window = g_new (MetaWindow, 1);
|
||||
|
||||
window->xwindow = xwindow;
|
||||
|
||||
window->screen = NULL;
|
||||
tmp = display->screens;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
if (((MetaScreen *)tmp->data)->xscreen == attrs.screen)
|
||||
{
|
||||
window->screen = tmp->data;
|
||||
break;
|
||||
}
|
||||
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
g_assert (window->screen);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void
|
||||
meta_window_free (MetaWindow *window)
|
||||
{
|
||||
g_free (window);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_window_event (MetaWindow *window,
|
||||
XEvent *event)
|
||||
{
|
||||
|
||||
/* consumed this event */
|
||||
return TRUE;
|
||||
}
|
40
src/window.h
Normal file
40
src/window.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* Metacity X managed windows */
|
||||
|
||||
/*
|
||||
* 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_WINDOW_H
|
||||
#define META_WINDOW_H
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
struct _MetaWindow
|
||||
{
|
||||
MetaScreen *screen;
|
||||
Window xwindow;
|
||||
};
|
||||
|
||||
MetaWindow* meta_window_new (MetaDisplay *display,
|
||||
Window xwindow);
|
||||
void meta_window_free (MetaWindow *window);
|
||||
|
||||
gboolean meta_window_event (MetaWindow *window,
|
||||
XEvent *event);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user