From 287b6b15d3840d6546bbc55f9dbd7b3d098429c3 Mon Sep 17 00:00:00 2001 From: rhp Date: Wed, 30 May 2001 15:36:31 +0000 Subject: [PATCH] ... --- src/display.c | 402 +++++++++++++++++++++++++++++++++++++++++++++++ src/display.h | 56 +++++++ src/eventqueue.c | 181 +++++++++++++++++++++ src/eventqueue.h | 39 +++++ src/main.c | 64 ++++++++ src/main.h | 41 +++++ src/screen.c | 53 +++++++ src/screen.h | 39 +++++ src/util.c | 119 ++++++++++++++ src/util.h | 42 +++++ src/window.c | 77 +++++++++ src/window.h | 40 +++++ 12 files changed, 1153 insertions(+) create mode 100644 src/display.c create mode 100644 src/display.h create mode 100644 src/eventqueue.c create mode 100644 src/eventqueue.h create mode 100644 src/main.c create mode 100644 src/main.h create mode 100644 src/screen.c create mode 100644 src/screen.h create mode 100644 src/util.c create mode 100644 src/util.h create mode 100644 src/window.c create mode 100644 src/window.h diff --git a/src/display.c b/src/display.c new file mode 100644 index 000000000..054407b7a --- /dev/null +++ b/src/display.c @@ -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); +} diff --git a/src/display.h b/src/display.h new file mode 100644 index 000000000..ec73a27ac --- /dev/null +++ b/src/display.h @@ -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 +#include +#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 diff --git a/src/eventqueue.c b/src/eventqueue.c new file mode 100644 index 000000000..1874b6554 --- /dev/null +++ b/src/eventqueue.c @@ -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 + +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 */ +} diff --git a/src/eventqueue.h b/src/eventqueue.h new file mode 100644 index 000000000..603314bff --- /dev/null +++ b/src/eventqueue.h @@ -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 +#include + +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 diff --git a/src/main.c b/src/main.c new file mode 100644 index 000000000..6f5c40e86 --- /dev/null +++ b/src/main.c @@ -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 + +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); +} + diff --git a/src/main.h b/src/main.h new file mode 100644 index 000000000..a5db63484 --- /dev/null +++ b/src/main.h @@ -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 + +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 diff --git a/src/screen.c b/src/screen.c new file mode 100644 index 000000000..e723cdab7 --- /dev/null +++ b/src/screen.c @@ -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); +} + + diff --git a/src/screen.h b/src/screen.h new file mode 100644 index 000000000..2c3d95cb3 --- /dev/null +++ b/src/screen.h @@ -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 diff --git a/src/util.c b/src/util.c new file mode 100644 index 000000000..73fe1a137 --- /dev/null +++ b/src/util.c @@ -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 + +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); +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 000000000..985b6332b --- /dev/null +++ b/src/util.h @@ -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 + +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 diff --git a/src/window.c b/src/window.c new file mode 100644 index 000000000..a8d9b9803 --- /dev/null +++ b/src/window.c @@ -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; +} diff --git a/src/window.h b/src/window.h new file mode 100644 index 000000000..66cc79fef --- /dev/null +++ b/src/window.h @@ -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