* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
cairo_image_surface_get_data (impl->surface));
}
+ broadway_output_surface_flush (output, impl->id);
+
cr = cairo_create (impl->last_surface);
cairo_set_source_surface (cr, impl->surface, 0, 0);
cairo_paint (cr);
}
}
- if (!broadway_output_flush (display->output))
- {
- display->saved_serial = broadway_output_get_next_serial (display->output);
- broadway_output_free (display->output);
- display->output = NULL;
- }
+ gdk_display_flush (GDK_DISPLAY (display));
return FALSE;
}
display = GDK_BROADWAY_DISPLAY (gdk_display_get_default ());
+ /* First create all windows */
for (l = display->toplevels; l != NULL; l = l->next)
{
GdkWindowImplBroadway *impl = l->data;
window->x,
window->y,
window->width,
- window->height);
- if (GDK_WINDOW_IS_MAPPED (window))
+ window->height,
+ window->window_type == GDK_WINDOW_TEMP);
+ }
+
+ /* Then do everything that may reference other windows */
+ for (l = display->toplevels; l != NULL; l = l->next)
+ {
+ GdkWindowImplBroadway *impl = l->data;
+
+ if (impl->id == 0)
+ continue; /* Skip root */
+
+ if (impl->transient_for)
+ broadway_output_set_transient_for (display->output, impl->id, impl->transient_for);
+ /* Can't check GDK_WINDOW_IS_MAPPED here, because that doesn't correctly handle
+ withdrawn windows like menus */
+ if (impl->visible)
{
broadway_output_show_surface (display->output, impl->id);
window_data_send (display->output, impl);
}
}
- broadway_output_flush (display->output);
+ gdk_display_flush (GDK_DISPLAY (display));
}
static void
{
impl->toplevel_window_type = -1;
impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) gdk_cursor_unref);
+ (GDestroyNotify) g_object_unref);
}
static void
wrapper = impl->wrapper;
+ _gdk_broadway_window_grab_check_destroy (wrapper);
+
broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (impl->wrapper));
if (broadway_display->mouse_in_toplevel == GDK_WINDOW (wrapper))
g_hash_table_remove (broadway_display->id_ht, GINT_TO_POINTER(impl->id));
if (impl->cursor)
- gdk_cursor_unref (impl->cursor);
+ g_object_unref (impl->cursor);
g_hash_table_destroy (impl->device_cursor);
gint attributes_mask)
{
GdkWindowImplBroadway *impl;
- GdkBroadwayScreen *broadway_screen;
GdkBroadwayDisplay *broadway_display;
static int current_id = 1; /* 0 is the root window */
broadway_display = GDK_BROADWAY_DISPLAY (display);
- broadway_screen = GDK_BROADWAY_SCREEN (screen);
impl = g_object_new (GDK_TYPE_WINDOW_IMPL_BROADWAY, NULL);
window->impl = (GdkWindowImpl *)impl;
broadway_display->toplevels = g_list_prepend (broadway_display->toplevels, impl);
- /* Instead of window manager placement we have this mini hack
- so that the main/first window is not covered in the demos. */
- if (impl->id > 1 && window->window_type == GDK_WINDOW_TOPLEVEL)
- {
- window->x = 100;
- window->y = 20;
- }
-
if (broadway_display->output)
broadway_output_new_surface (broadway_display->output,
impl->id,
window->x,
window->y,
window->width,
- window->height);
+ window->height,
+ window->window_type == GDK_WINDOW_TEMP);
}
-static void
-resize_surface (GdkWindow *window)
+void
+_gdk_broadway_window_resize_surface (GdkWindow *window)
{
GdkWindowImplBroadway *impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
cairo_surface_t *old, *last_old;
gdk_window_get_width (impl->wrapper),
gdk_window_get_height (impl->wrapper));
- { cairo_t *cr;
- cr = cairo_create (impl->surface);
- cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
- cairo_rectangle (cr, 0, 0, 1000, 1000);
- cairo_fill (cr);
- cairo_destroy (cr);
- }
-
cairo_surface_destroy (old);
cairo_surface_destroy (last_old);
}
NULL, NULL);
impl->ref_surface = NULL;
}
+
+ gdk_window_invalidate_rect (window, NULL, TRUE);
}
static void
impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
_gdk_broadway_selection_window_destroyed (window);
+ _gdk_broadway_window_grab_check_destroy (window);
if (impl->ref_surface)
{
}
broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (window));
+ g_hash_table_remove (broadway_display->id_ht, GINT_TO_POINTER(impl->id));
+
if (broadway_display->output)
broadway_output_destroy_surface (broadway_display->output,
impl->id);
static void
gdk_broadway_window_destroy_notify (GdkWindow *window)
{
- GdkWindowImplBroadway *window_impl;
-
- window_impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
-
if (!GDK_WINDOW_DESTROYED (window))
{
if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
GdkBroadwayDisplay *broadway_display;
impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+ impl->visible = TRUE;
if (window->event_mask & GDK_STRUCTURE_MASK)
_gdk_make_event (GDK_WINDOW (window), GDK_MAP, NULL, FALSE);
GdkBroadwayDisplay *broadway_display;
impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+ impl->visible = FALSE;
if (window->event_mask & GDK_STRUCTURE_MASK)
_gdk_make_event (GDK_WINDOW (window), GDK_UNMAP, NULL, FALSE);
{
GdkWindowImplBroadway *impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
GdkBroadwayDisplay *broadway_display;
- gboolean changed;
+ gboolean changed, size_changed;;
+ gboolean with_resize;
- changed = FALSE;
+ size_changed = changed = FALSE;
broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (window));
if (with_move)
changed = TRUE;
window->x = x;
window->y = y;
- if (broadway_display->output != NULL)
- {
- broadway_output_move_surface (broadway_display->output,
- impl->id, x, y);
- queue_dirty_flush (broadway_display);
- }
}
-
+ with_resize = FALSE;
if (width > 0 || height > 0)
{
+ with_resize = TRUE;
if (width < 1)
width = 1;
height != window->height)
{
changed = TRUE;
+ size_changed = TRUE;
/* Resize clears the content */
impl->dirty = TRUE;
impl->last_synced = FALSE;
- broadway_output_resize_surface (broadway_display->output,
- impl->id, width, height);
- queue_dirty_flush (broadway_display);
-
window->width = width;
window->height = height;
- resize_surface (window);
- gdk_window_invalidate_rect (window, NULL, TRUE);
+ _gdk_broadway_window_resize_surface (window);
}
}
GdkEvent *event;
GList *node;
+ if (broadway_display->output != NULL)
+ {
+ broadway_output_move_resize_surface (broadway_display->output,
+ impl->id,
+ with_move, window->x, window->y,
+ with_resize, window->width, window->height);
+ queue_dirty_flush (broadway_display);
+ if (size_changed)
+ window->resize_count++;
+ }
+
event = gdk_event_new (GDK_CONFIGURE);
event->configure.window = g_object_ref (window);
event->configure.x = window->x;
static gboolean
gdk_window_broadway_reparent (GdkWindow *window,
- GdkWindow *new_parent,
- gint x,
- gint y)
+ GdkWindow *new_parent,
+ gint x,
+ gint y)
{
return FALSE;
}
static void
gdk_window_broadway_restack_under (GdkWindow *window,
- GList *native_siblings /* in requested order, first is bottom-most */)
+ GList *native_siblings /* in requested order, first is bottom-most */)
{
}
static void
gdk_window_broadway_restack_toplevel (GdkWindow *window,
- GdkWindow *sibling,
- gboolean above)
+ GdkWindow *sibling,
+ gboolean above)
{
}
gdk_broadway_window_set_transient_for (GdkWindow *window,
GdkWindow *parent)
{
+ GdkBroadwayDisplay *display;
+ GdkWindowImplBroadway *impl;
+ int parent_id;
+
+ impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+
+ parent_id = 0;
+ if (parent)
+ parent_id = GDK_WINDOW_IMPL_BROADWAY (parent->impl)->id;
+
+ impl->transient_for = parent_id;
+
+ display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (impl->wrapper));
+ if (display->output)
+ {
+ broadway_output_set_transient_for (display->output, impl->id, impl->transient_for);
+ gdk_display_flush (GDK_DISPLAY (display));
+ }
}
static void
gint *width,
gint *height)
{
+ GdkWindowImplBroadway *impl;
+
+ g_return_if_fail (GDK_IS_WINDOW (window));
+
+ impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+
+ /* TODO: These should really roundtrip to the client to get the current data */
+
+ if (x)
+ *x = impl->wrapper->x;
+ if (y)
+ *y = impl->wrapper->y;
+ if (width)
+ *width = impl->wrapper->width;
+ if (height)
+ *height = impl->wrapper->height;
+
}
static gint
gdk_window_broadway_get_root_coords (GdkWindow *window,
- gint x,
- gint y,
- gint *root_x,
- gint *root_y)
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y)
{
+ GdkWindowImplBroadway *impl;
+
+ impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+
if (root_x)
- *root_x = x;
+ *root_x = x + impl->wrapper->x;
if (root_y)
- *root_y = y;
+ *root_y = y + impl->wrapper->y;
return 1;
}
gint *x,
gint *y)
{
+ GdkWindowImplBroadway *impl;
+
+ impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+
+ /* TODO: This should take wm frame into account */
+
if (x)
- *x = 0;
+ *x = impl->wrapper->x;
if (y)
- *y = 0;
+ *y = impl->wrapper->x;
}
static void
{
g_return_if_fail (rect != NULL);
+ /* TODO: This should take wm frame into account */
+
rect->x = window->x;
rect->y = window->y;
rect->width = window->width;
gint *y,
GdkModifierType *mask)
{
- *x = 0;
- *y = 0;
- *mask = 0;
- return FALSE;
+ GdkWindow *child;
+
+ g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
+
+ if (GDK_WINDOW_DESTROYED (window))
+ return FALSE;
+
+ GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
+ NULL, &child,
+ NULL, NULL,
+ x, y, mask);
+ return child != NULL;
}
static GdkEventMask
}
static void
-gdk_broadway_window_set_icon_name (GdkWindow *window,
+gdk_broadway_window_set_icon_name (GdkWindow *window,
const gchar *name)
{
- GdkDisplay *display;
-
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
- display = gdk_window_get_display (window);
-
g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
- GUINT_TO_POINTER (name != NULL));
+ GUINT_TO_POINTER (name != NULL));
}
static void
return TRUE;
}
+typedef struct _MoveResizeData MoveResizeData;
+
+struct _MoveResizeData
+{
+ GdkDisplay *display;
+
+ GdkWindow *moveresize_window;
+ GdkWindow *moveresize_emulation_window;
+ gboolean is_resize;
+ GdkWindowEdge resize_edge;
+ gint moveresize_button;
+ gint moveresize_x;
+ gint moveresize_y;
+ gint moveresize_orig_x;
+ gint moveresize_orig_y;
+ gint moveresize_orig_width;
+ gint moveresize_orig_height;
+ long moveresize_process_time;
+ BroadwayInputMsg *moveresize_pending_event;
+};
+
+static MoveResizeData *
+get_move_resize_data (GdkDisplay *display,
+ gboolean create)
+{
+ MoveResizeData *mv_resize;
+ static GQuark move_resize_quark = 0;
+
+ if (!move_resize_quark)
+ move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
+
+ mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
+
+ if (!mv_resize && create)
+ {
+ mv_resize = g_new0 (MoveResizeData, 1);
+ mv_resize->display = display;
+
+ g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
+ }
+
+ return mv_resize;
+}
+
+static void
+update_pos (MoveResizeData *mv_resize,
+ gint new_root_x,
+ gint new_root_y)
+{
+ gint dx, dy;
+
+ dx = new_root_x - mv_resize->moveresize_x;
+ dy = new_root_y - mv_resize->moveresize_y;
+
+ if (mv_resize->is_resize)
+ {
+ gint x, y, w, h;
+
+ x = mv_resize->moveresize_orig_x;
+ y = mv_resize->moveresize_orig_y;
+
+ w = mv_resize->moveresize_orig_width;
+ h = mv_resize->moveresize_orig_height;
+
+ switch (mv_resize->resize_edge)
+ {
+ case GDK_WINDOW_EDGE_NORTH_WEST:
+ x += dx;
+ y += dy;
+ w -= dx;
+ h -= dy;
+ break;
+ case GDK_WINDOW_EDGE_NORTH:
+ y += dy;
+ h -= dy;
+ break;
+ case GDK_WINDOW_EDGE_NORTH_EAST:
+ y += dy;
+ h -= dy;
+ w += dx;
+ break;
+ case GDK_WINDOW_EDGE_SOUTH_WEST:
+ h += dy;
+ x += dx;
+ w -= dx;
+ break;
+ case GDK_WINDOW_EDGE_SOUTH_EAST:
+ w += dx;
+ h += dy;
+ break;
+ case GDK_WINDOW_EDGE_SOUTH:
+ h += dy;
+ break;
+ case GDK_WINDOW_EDGE_EAST:
+ w += dx;
+ break;
+ case GDK_WINDOW_EDGE_WEST:
+ x += dx;
+ w -= dx;
+ break;
+ }
+
+ x = MAX (x, 0);
+ y = MAX (y, 0);
+ w = MAX (w, 1);
+ h = MAX (h, 1);
+
+ gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
+ }
+ else
+ {
+ gint x, y;
+
+ x = mv_resize->moveresize_orig_x + dx;
+ y = mv_resize->moveresize_orig_y + dy;
+
+ gdk_window_move (mv_resize->moveresize_window, x, y);
+ }
+}
+
+static void
+finish_drag (MoveResizeData *mv_resize)
+{
+ gdk_window_destroy (mv_resize->moveresize_emulation_window);
+ mv_resize->moveresize_emulation_window = NULL;
+ g_object_unref (mv_resize->moveresize_window);
+ mv_resize->moveresize_window = NULL;
+
+ if (mv_resize->moveresize_pending_event)
+ {
+ g_free (mv_resize->moveresize_pending_event);
+ mv_resize->moveresize_pending_event = NULL;
+ }
+}
+
+static gboolean
+moveresize_lookahead (GdkDisplay *display,
+ MoveResizeData *mv_resize,
+ BroadwayInputMsg *event)
+{
+ GdkBroadwayDisplay *broadway_display;
+ BroadwayInputMsg *message;
+ GList *l;
+
+ broadway_display = GDK_BROADWAY_DISPLAY (display);
+ for (l = broadway_display->input_messages; l != NULL; l = l->next)
+ {
+ message = l->data;
+ if (message->base.type == 'm')
+ return FALSE;
+ if (message->base.type == 'b')
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
+_gdk_broadway_moveresize_handle_event (GdkDisplay *display,
+ BroadwayInputMsg *event)
+{
+ guint button_mask = 0;
+ MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
+
+ if (!mv_resize || !mv_resize->moveresize_window)
+ return FALSE;
+
+ button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
+
+ switch (event->base.type)
+ {
+ case 'm':
+ if (mv_resize->moveresize_window->resize_count > 0)
+ {
+ if (mv_resize->moveresize_pending_event)
+ *mv_resize->moveresize_pending_event = *event;
+ else
+ mv_resize->moveresize_pending_event =
+ g_memdup (event, sizeof (BroadwayInputMsg));
+
+ break;
+ }
+ if (!moveresize_lookahead (display, mv_resize, event))
+ break;
+
+ update_pos (mv_resize,
+ event->pointer.root_x,
+ event->pointer.root_y);
+
+ /* This should never be triggered in normal cases, but in the
+ * case where the drag started without an implicit grab being
+ * in effect, we could miss the release if it occurs before
+ * we grab the pointer; this ensures that we will never
+ * get a permanently stuck grab.
+ */
+ if ((event->pointer.state & button_mask) == 0)
+ finish_drag (mv_resize);
+ break;
+
+ case 'B':
+ update_pos (mv_resize,
+ event->pointer.root_x,
+ event->pointer.root_y);
+
+ if (event->button.button == mv_resize->moveresize_button)
+ finish_drag (mv_resize);
+ break;
+ }
+ return TRUE;
+}
+
+gboolean
+_gdk_broadway_moveresize_configure_done (GdkDisplay *display,
+ GdkWindow *window)
+{
+ BroadwayInputMsg *tmp_event;
+ MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
+
+ if (!mv_resize || window != mv_resize->moveresize_window)
+ return FALSE;
+
+ if (mv_resize->moveresize_pending_event)
+ {
+ tmp_event = mv_resize->moveresize_pending_event;
+ mv_resize->moveresize_pending_event = NULL;
+ _gdk_broadway_moveresize_handle_event (display, tmp_event);
+ g_free (tmp_event);
+ }
+
+ return TRUE;
+}
+
+static void
+create_moveresize_window (MoveResizeData *mv_resize,
+ guint32 timestamp)
+{
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GdkGrabStatus status;
+
+ g_assert (mv_resize->moveresize_emulation_window == NULL);
+
+ attributes.x = -100;
+ attributes.y = -100;
+ attributes.width = 10;
+ attributes.height = 10;
+ attributes.window_type = GDK_WINDOW_TEMP;
+ attributes.wclass = GDK_INPUT_ONLY;
+ attributes.override_redirect = TRUE;
+ attributes.event_mask = 0;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
+
+ mv_resize->moveresize_emulation_window =
+ gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
+ &attributes,
+ attributes_mask);
+
+ gdk_window_show (mv_resize->moveresize_emulation_window);
+
+ status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
+ FALSE,
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_MASK,
+ NULL,
+ NULL,
+ timestamp);
+
+ if (status != GDK_GRAB_SUCCESS)
+ {
+ /* If this fails, some other client has grabbed the window
+ * already.
+ */
+ finish_drag (mv_resize);
+ }
+
+ mv_resize->moveresize_process_time = 0;
+}
+
static void
gdk_broadway_window_begin_resize_drag (GdkWindow *window,
- GdkWindowEdge edge,
- gint button,
- gint root_x,
- gint root_y,
- guint32 timestamp)
+ GdkWindowEdge edge,
+ GdkDevice *device,
+ gint button,
+ gint root_x,
+ gint root_y,
+ guint32 timestamp)
{
+ GdkBroadwayDisplay *broadway_display;
+ MoveResizeData *mv_resize;
+
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
+ /* We need a connection to be able to get mouse events, if not, punt */
+ broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (window));
+ if (!broadway_display->output)
+ return;
+
+ mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
+
+ mv_resize->is_resize = TRUE;
+ mv_resize->moveresize_button = button;
+ mv_resize->resize_edge = edge;
+ mv_resize->moveresize_x = root_x;
+ mv_resize->moveresize_y = root_y;
+ mv_resize->moveresize_window = g_object_ref (window);
+
+ gdk_window_get_origin (mv_resize->moveresize_window,
+ &mv_resize->moveresize_orig_x,
+ &mv_resize->moveresize_orig_y);
+ mv_resize->moveresize_orig_width = gdk_window_get_width (window);
+ mv_resize->moveresize_orig_height = gdk_window_get_height (window);
+
+ create_moveresize_window (mv_resize, timestamp);
}
static void
gdk_broadway_window_begin_move_drag (GdkWindow *window,
+ GdkDevice *device,
gint button,
gint root_x,
gint root_y,
gdk_broadway_window_set_opacity (GdkWindow *window,
gdouble opacity)
{
- GdkDisplay *display;
-
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL (window))
return;
- display = gdk_window_get_display (window);
-
if (opacity < 0)
opacity = 0;
else if (opacity > 1)
opacity = 1;
-
}
static void
gdk_broadway_window_set_composited (GdkWindow *window,
- gboolean composited)
+ gboolean composited)
{
}
if (impl->surface)
{
copy_region (impl->surface, area, dx, dy);
- if (GDK_WINDOW_IMPL_BROADWAY (impl)->last_synced)
+ broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (window));
+ if (GDK_WINDOW_IMPL_BROADWAY (impl)->last_synced &&
+ broadway_display->output)
{
copy_region (impl->last_surface, area, dx, dy);
n_rects = cairo_region_num_rectangles (area);
rects[i].width = rect.width;
rects[i].height = rect.height;
}
- broadway_display = GDK_BROADWAY_DISPLAY (gdk_window_get_display (window));
broadway_output_copy_rectangles (broadway_display->output,
GDK_WINDOW_IMPL_BROADWAY (impl)->id,
rects, n_rects, dx, dy);
}
}
+guint32
+gdk_broadway_get_last_seen_time (GdkWindow *window)
+{
+ GdkDisplay *display;
+
+ display = gdk_window_get_display (window);
+ _gdk_broadway_display_consume_all_input (display);
+ return (guint32) GDK_BROADWAY_DISPLAY (display)->last_seen_time;
+}
+
static void
gdk_window_impl_broadway_class_init (GdkWindowImplBroadwayClass *klass)
{