Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
dock-support: Update the dock-support API to better match the new API…
Browse files Browse the repository at this point in the history
… added to libXplugin

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
  • Loading branch information
jeremyhu committed Apr 27, 2012
1 parent 330b55e commit 21f210c
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 80 deletions.
102 changes: 67 additions & 35 deletions lib/dock-support.h
Expand Up @@ -25,58 +25,90 @@
#ifndef __DOCK_SUPPORT_H__
#define __DOCK_SUPPORT_H__

#include <Xplugin.h>
#include <ApplicationServices/ApplicationServices.h>
#include <objc/objc.h>

typedef uint32_t qwm_native_window_id;
#ifdef XPLUGIN_DOCK_SUPPORT

#define QWM_NULL_NATIVE_WINDOW_ID ((qwm_native_window_id)0)
#if !defined(XPLUGIN_VERSION) || XPLUGIN_VERSION < 5
#error "The installed version of libXplugin is not recent enough to support quartz-wm. Please reconfigure and use the provided libquartz-wm-ds instead."
#endif

/* Dock location */
typedef enum {
QWM_DOCK_ORIENTATION_BOTTOM = 2,
QWM_DOCK_ORIENTATION_LEFT = 3,
QWM_DOCK_ORIENTATION_RIGHT = 4,
} qwm_dock_orientation;
#define qwm_dock_get_orientation xp_dock_get_orientation
#define qwm_dock_get_rect xp_dock_get_rect
#define qwm_dock_is_window_visible xp_dock_is_window_visible
#define qwm_dock_minimize_item_with_title_async xp_dock_minimize_item_with_title_async
#define qwm_dock_restore_item_async xp_dock_restore_item_async
#define qwm_dock_remove_item xp_dock_remove_item
#define qwm_dock_drag_begin xp_dock_drag_begin
#define qwm_dock_drag_end xp_dock_drag_end
#define qwm_dock_event_set_handler xp_dock_event_set_handler

extern qwm_dock_orientation qwm_dock_get_orientation(void);
extern CGRect qwm_dock_get_rect(void);
static inline void qwm_dock_init(bool only_proxy) {
int options = XP_IN_BACKGROUND;

/* Window Visibility */
extern CGError qwm_dock_is_window_visible(qwm_native_window_id window_id, BOOL *is_visible);
if (!only_proxy)
options |= XP_DOCK_SUPPORT;
xp_init(options);
}

/* Minimize / Restore */
extern OSStatus qwm_dock_minimize_item_with_title_async(qwm_native_window_id osxwindow_id, CFStringRef title);
extern OSStatus qwm_dock_restore_item_async(qwm_native_window_id osxwindow_id);
extern OSStatus qwm_dock_remove_item(qwm_native_window_id osxwindow_id);
#else

/* Window dragging */
extern OSStatus qwm_dock_drag_begin(qwm_native_window_id osxwindow_id);
extern OSStatus qwm_dock_drag_end(qwm_native_window_id osxwindow_id);
/* If our Xplugin headers aren't new enough, provide missing types */
#if !defined(XPLUGIN_VERSION) || XPLUGIN_VERSION < 5
typedef unsigned int xp_native_window_id;

/* Initialization */
extern void qwm_dock_init(bool only_proxy);
#define XP_NULL_NATIVE_WINDOW_ID ((xp_native_window_id)0)

/* Dock location */
enum xp_dock_orientation_enum {
XP_DOCK_ORIENTATION_BOTTOM = 2,
XP_DOCK_ORIENTATION_LEFT = 3,
XP_DOCK_ORIENTATION_RIGHT = 4,
};
typedef enum xp_dock_orientation_enum xp_dock_orientation;

/* Event handling */
typedef enum {
QWM_DOCK_EVENT_RESTORE_ALL_WINDOWS = 1,
QWM_DOCK_EVENT_RESTORE_WINDOWS = 2,
QWM_DOCK_EVENT_SELECT_WINDOWS = 3,
QWM_DOCK_EVENT_RESTORE_DONE = 4,
QWM_DOCK_EVENT_MINIMIZE_DONE = 5,
} qwm_dock_event_type;
XP_DOCK_EVENT_RESTORE_ALL_WINDOWS = 1,
XP_DOCK_EVENT_RESTORE_WINDOWS = 2,
XP_DOCK_EVENT_SELECT_WINDOWS = 3,
XP_DOCK_EVENT_RESTORE_DONE = 4,
XP_DOCK_EVENT_MINIMIZE_DONE = 5,
} xp_dock_event_type;

typedef struct {
qwm_dock_event_type type;
xp_dock_event_type type;

/* XP_NULL_NATIVE_WINDOW_ID terminated list of windows affected by this event */
xp_native_window_id *windows;

/* QWM_NULL_NATIVE_WINDOW_ID terminated list of windows affected by this event */
qwm_native_window_id *windows;
/* YES if the event was successful (for XP_DOCK_EVENT_RESTORE_DONE and XP_DOCK_EVENT_MINIMIZE_DONE) */
xp_bool success;
} xp_dock_event;

/* YES if the event was successful (for QWM_DOCK_EVENT_RESTORE_DONE and QWM_DOCK_EVENT_MINIMIZE_DONE) */
BOOL success;
} qwm_dock_event;
typedef void (*xp_dock_event_handler)(xp_dock_event *event);
#endif

typedef void (*qwm_dock_event_handler)(qwm_dock_event *event);
extern void qwm_dock_event_set_handler(qwm_dock_event_handler new_handler);
extern xp_dock_orientation qwm_dock_get_orientation(void);
extern xp_box qwm_dock_get_rect(void);

/* Window Visibility */
extern xp_error qwm_dock_is_window_visible(xp_native_window_id osxwindow_id, xp_bool *is_visible);

/* Minimize / Restore */
extern xp_error qwm_dock_minimize_item_with_title_async(xp_native_window_id osxwindow_id, const char * title);
extern xp_error qwm_dock_restore_item_async(xp_native_window_id osxwindow_id);
extern xp_error qwm_dock_remove_item(xp_native_window_id osxwindow_id);

/* Window dragging */
extern xp_error qwm_dock_drag_begin(xp_native_window_id osxwindow_id);
extern xp_error qwm_dock_drag_end(xp_native_window_id osxwindow_id);

/* Initialization */
extern void qwm_dock_init(bool only_proxy);
extern void qwm_dock_event_set_handler(xp_dock_event_handler new_handler);

#endif /* XPLUGIN_DOCK_SUPPORT */
#endif /* __DOCK_SUPPORT_H__ */
Binary file modified lib/libquartz-wm-ds.apsl.dylib
Binary file not shown.
8 changes: 6 additions & 2 deletions src/Makefile.am
Expand Up @@ -21,14 +21,18 @@

bin_PROGRAMS = quartz-wm

AM_CPPFLAGS = -I$(top_srcdir)/lib
AM_CPPFLAGS = -I$(top_srcdir)/lib -DXP_NO_X_HEADERS
AM_OBJCFLAGS = $(QUARTZWM_CFLAGS) $(CWARNFLAGS)
AM_CFLAGS = $(QUARTZWM_CFLAGS) $(CWARNFLAGS)

quartz_wm_LDFLAGS = $(QUARTZWM_LIBS) \
-L$(top_builddir)/lib -lquartz-wm-ds \
-framework AppKit

#AM_CPPFLAGS += -DXPLUGIN_DOCK_SUPPORT
#quartz_wm_LDFLAGS += -lXplugin

quartz_wm_LDFLAGS += -L$(top_builddir)/lib -lquartz-wm-ds

quartz_wm_SOURCES = \
dock-support-handler.m \
frame.h \
Expand Down
28 changes: 14 additions & 14 deletions src/dock-support-handler.m
Expand Up @@ -35,14 +35,14 @@

#include "dock-support.h"

void dock_event_handler(qwm_dock_event *event) {
void dock_event_handler(xp_dock_event *event) {
x_list *s_node = NULL, *w_node = NULL;
x_window *w = NULL;
x_screen *s = NULL;
qwm_native_window_id *native_wid;
xp_native_window_id *native_wid;

switch (event->type) {
case QWM_DOCK_EVENT_RESTORE_ALL_WINDOWS:
case XP_DOCK_EVENT_RESTORE_ALL_WINDOWS:
for (s_node = screen_list; s_node != NULL; s_node = s_node->next) {
s = s_node->data;
for (w_node = s->_window_list; w_node != NULL; w_node = w_node->next) {
Expand All @@ -54,33 +54,33 @@ void dock_event_handler(qwm_dock_event *event) {
}
}
break;
case QWM_DOCK_EVENT_RESTORE_WINDOWS:
case QWM_DOCK_EVENT_SELECT_WINDOWS:
case QWM_DOCK_EVENT_RESTORE_DONE:
case QWM_DOCK_EVENT_MINIMIZE_DONE:
if (event->type == QWM_DOCK_EVENT_RESTORE_WINDOWS ||
event->type == QWM_DOCK_EVENT_SELECT_WINDOWS)
case XP_DOCK_EVENT_RESTORE_WINDOWS:
case XP_DOCK_EVENT_SELECT_WINDOWS:
case XP_DOCK_EVENT_RESTORE_DONE:
case XP_DOCK_EVENT_MINIMIZE_DONE:
if (event->type == XP_DOCK_EVENT_RESTORE_WINDOWS ||
event->type == XP_DOCK_EVENT_SELECT_WINDOWS)
XAppleWMSetFrontProcess (x_dpy);

for (native_wid = event->windows; *native_wid != QWM_NULL_NATIVE_WINDOW_ID; native_wid++) {
for (native_wid = event->windows; *native_wid != XP_NULL_NATIVE_WINDOW_ID; native_wid++) {
w = x_get_window_by_osx_id (*native_wid);
if (w == NULL) {
DB("Invalid native window id: %u\n", *native_wid);
return;
}

switch (event->type) {
case QWM_DOCK_EVENT_RESTORE_WINDOWS:
case XP_DOCK_EVENT_RESTORE_WINDOWS:
[w do_uncollapse_and_tell_dock:FALSE];
[w activate:CurrentTime];
break;
case QWM_DOCK_EVENT_SELECT_WINDOWS:
case XP_DOCK_EVENT_SELECT_WINDOWS:
[w activate:CurrentTime];
break;
case QWM_DOCK_EVENT_RESTORE_DONE:
case XP_DOCK_EVENT_RESTORE_DONE:
[w uncollapse_finished:event->success];
break;
case QWM_DOCK_EVENT_MINIMIZE_DONE:
case XP_DOCK_EVENT_MINIMIZE_DONE:
[w collapse_finished:event->success];
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/main.m
Expand Up @@ -572,7 +572,7 @@ static void x_error_shutdown (void) {
}

id
x_get_window_by_osx_id (qwm_native_window_id osxwindow_id)
x_get_window_by_osx_id (xp_native_window_id osxwindow_id)
{
x_list *node;

Expand Down
4 changes: 2 additions & 2 deletions src/quartz-wm.h
Expand Up @@ -89,7 +89,7 @@ extern void x_update_keymap (void);
extern id x_get_screen (Screen *xs);
extern id x_get_screen_with_root (Window xwindow_id);
extern id x_get_window (Window xwindow_id);
extern id x_get_window_by_osx_id (qwm_native_window_id osxwindow_id);
extern id x_get_window_by_osx_id (xp_native_window_id osxwindow_id);
extern void x_set_active_window (id w);
extern id x_get_active_window (void);
extern void x_set_is_active (BOOL state);
Expand Down Expand Up @@ -193,7 +193,7 @@ extern struct atoms_struct_t atoms;

/* Dock Events */
#include "dock-support.h"
extern void dock_event_handler(qwm_dock_event *event);
extern void dock_event_handler(xp_dock_event *event);

/* Debugging support */
extern void debug_printf (const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2);
Expand Down
2 changes: 1 addition & 1 deletion src/x-screen.h
Expand Up @@ -81,7 +81,7 @@
- (void) unadopt_windows;
- (void) error_shutdown;
- get_window:(Window)xwindow_id;
- get_window_by_osx_id:(qwm_native_window_id)id;
- get_window_by_osx_id:(xp_native_window_id)id;
- (X11Rect) validate_window_position:(X11Rect)r titlebar_height:(size_t)titlebar_height;
- (X11Rect) zoomed_rect:(X11Point)p;
- (X11Rect) zoomed_rect;
Expand Down
20 changes: 12 additions & 8 deletions src/x-screen.m
Expand Up @@ -444,7 +444,7 @@ - (void) focus_topmost:(Time)timestamp
x_window *w;
x_list *sl;
CGError err;
BOOL isVisible;
xp_bool isVisible;

for(sl = _stacking_list; sl; sl = sl->next) {
w = sl->data;
Expand Down Expand Up @@ -632,14 +632,14 @@ - (void) error_shutdown
return nil;
}

- get_window_by_osx_id:(qwm_native_window_id)osxwindow_id
- get_window_by_osx_id:(xp_native_window_id)osxwindow_id
{
x_list *node;

for (node = _window_list; node != NULL; node = node->next)
{
x_window *w = node->data;
qwm_native_window_id wid;
xp_native_window_id wid;

if (w->_deleted)
continue;
Expand All @@ -660,13 +660,17 @@ - (X11Rect) validate_window_position:(X11Rect)win_rect titlebar_height:(size_t)t
X11Rect title_rect, title_int_rect;
X11Rect ret, dock_rect;
pixman_box32_t *e;
xp_box dock_box;

TRACE();

// Figure out where the dock is to handle
// <rdar://problem/7595340> X11 window can get lost under the dock
// http://xquartz.macosforge.org/trac/ticket/329
dock_rect = [self CGToX11Rect:qwm_dock_get_rect()];
dock_box = qwm_dock_get_rect();
dock_rect = [self CGToX11Rect:CGRectMake(dock_box.x1, dock_box.y1,
dock_box.x2 - dock_box.x1,
dock_box.y2 - dock_box.y1)];

ret = title_rect = win_rect;
title_rect.height = titlebar_height;
Expand Down Expand Up @@ -731,13 +735,13 @@ - (X11Rect) validate_window_position:(X11Rect)win_rect titlebar_height:(size_t)t
} else {
/* Window is partially behind our dock. */
switch(qwm_dock_get_orientation()) {
case QWM_DOCK_ORIENTATION_BOTTOM:
case XP_DOCK_ORIENTATION_BOTTOM:
ret.y = dock_rect.y - titlebar_height;
break;
case QWM_DOCK_ORIENTATION_LEFT:
case XP_DOCK_ORIENTATION_LEFT:
ret.x = dock_rect.x + dock_rect.width - ret.width + 40;
break;
case QWM_DOCK_ORIENTATION_RIGHT:
case XP_DOCK_ORIENTATION_RIGHT:
ret.x = dock_rect.x - 40;
break;
default:
Expand Down Expand Up @@ -767,7 +771,7 @@ - (X11Rect) validate_window_position:(X11Rect)win_rect titlebar_height:(size_t)t

dpy_rect = _heads[i];

if(qwm_dock_get_orientation() == QWM_DOCK_ORIENTATION_BOTTOM &&
if(qwm_dock_get_orientation() == XP_DOCK_ORIENTATION_BOTTOM &&
X11RectContainsPoint(dpy_rect, X11PointMake(dock_rect.x, dock_rect.y)))
dock_bottom_height = dock_rect.height;

Expand Down
6 changes: 3 additions & 3 deletions src/x-window.h
Expand Up @@ -131,8 +131,8 @@
xp_frame_class _drawn_frame_decor;

/* Mac IDs corresponding to these windows */
qwm_native_window_id _osx_id;
qwm_native_window_id _minimized_osx_id;
xp_native_window_id _osx_id;
xp_native_window_id _minimized_osx_id;

/* Transience tree */
Window _transient_for_id;
Expand All @@ -155,7 +155,7 @@
- (void) property_changed:(Atom)atom;
- (void) update_net_wm_action_property;
- (x_list *) window_group;
- (qwm_native_window_id) get_osx_id;
- (xp_native_window_id) get_osx_id;
- (void) set_wm_state:(int)state;
- (void) raise;
- (BOOL) focus:(Time)timestamp;
Expand Down

0 comments on commit 21f210c

Please sign in to comment.