summaryrefslogtreecommitdiff
path: root/openbox
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-04-17 05:28:35 +0000
committerDana Jansens <danakj@orodu.net>2003-04-17 05:28:35 +0000
commit7886b797a36f5a035a75a19424e0b3cf7825baf8 (patch)
treed7279da4dbeda975909f71af3193a39ce7e69901 /openbox
parent55c424d38bb119bd04199ed5e73b035b00474dd9 (diff)
move the move/resize functionality into moveresize.c, for use with the netwm atoms. use it from teh plugins. combine the two actions.
Diffstat (limited to 'openbox')
-rw-r--r--openbox/Makefile.am4
-rw-r--r--openbox/action.c100
-rw-r--r--openbox/action.h22
-rw-r--r--openbox/event.c9
-rw-r--r--openbox/moveresize.c192
-rw-r--r--openbox/moveresize.h14
-rw-r--r--openbox/prop.c21
-rw-r--r--openbox/prop.h10
8 files changed, 259 insertions, 113 deletions
diff --git a/openbox/Makefile.am b/openbox/Makefile.am
index 5c5d39d8..d1af4683 100644
--- a/openbox/Makefile.am
+++ b/openbox/Makefile.am
@@ -23,12 +23,12 @@ openbox3_LDFLAGS=-export-dynamic
openbox3_SOURCES=parse.tab.c parse.lex.c action.c client.c config.c \
extensions.c focus.c frame.c grab.c menu.c openbox.c \
framerender.c parse.c plugin.c prop.c screen.c stacking.c \
- dispatch.c event.c group.c timer.c xerror.c
+ dispatch.c event.c group.c timer.c xerror.c moveresize.c
noinst_HEADERS=action.h client.h config.h dispatch.h event.h extensions.h \
focus.h frame.h framerender.h geom.h gettext.h grab.h group.h \
menu.h openbox.h parse.h parse.tab.h plugin.h prop.h screen.h \
- stacking.h timer.h xerror.h
+ stacking.h timer.h xerror.h moveresize.h
# kill the implicit .c.y rule
%.c: %.y
diff --git a/openbox/action.c b/openbox/action.c
index 888c04e5..1740d1b1 100644
--- a/openbox/action.c
+++ b/openbox/action.c
@@ -1,7 +1,9 @@
#include "client.h"
#include "grab.h"
#include "focus.h"
+#include "moveresize.h"
#include "menu.h"
+#include "prop.h"
#include "stacking.h"
#include "frame.h"
#include "framerender.h"
@@ -151,10 +153,18 @@ Action *action_from_string(char *name)
a->data.nextprevdesktop.wrap = TRUE;
} else if (!g_ascii_strcasecmp(name, "toggledecorations")) {
a = action_new(action_toggle_decorations);
+ } else if (!g_ascii_strcasecmp(name, "keyboardmove")) {
+ a = action_new(action_moveresize);
+ a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move_keyboard;
} else if (!g_ascii_strcasecmp(name, "move")) {
- a = action_new(action_move);
+ a = action_new(action_moveresize);
+ a->data.moveresize.corner = prop_atoms.net_wm_moveresize_move;
} else if (!g_ascii_strcasecmp(name, "resize")) {
- a = action_new(action_resize);
+ a = action_new(action_moveresize);
+ a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_topleft;
+ } else if (!g_ascii_strcasecmp(name, "keyboardresize")) {
+ a = action_new(action_moveresize);
+ a->data.moveresize.corner = prop_atoms.net_wm_moveresize_size_keyboard;
} else if (!g_ascii_strcasecmp(name, "restart")) {
a = action_new(action_restart);
} else if (!g_ascii_strcasecmp(name, "exit")) {
@@ -628,92 +638,14 @@ void action_toggle_decorations(union ActionData *data)
client_setup_decor_and_functions(c);
}
-static void popup_coords(char *format, Cursor cur, int a, int b, gboolean hide)
+void action_moveresize(union ActionData *data)
{
- XSetWindowAttributes attrib;
- static Window coords = None;
-
- if (coords == None) {
- attrib.override_redirect = TRUE;
- coords = XCreateWindow(ob_display, ob_root,
- 0, 0, 1, 1, 0, render_depth, InputOutput,
- render_visual, CWOverrideRedirect, &attrib);
- g_assert(coords != None);
-
- grab_pointer(TRUE, cur);
-
- XMapWindow(ob_display, coords);
- }
-
- if (hide) {
- XDestroyWindow(ob_display, coords);
- coords = None;
-
- grab_pointer(FALSE, None);
- } else {
- Size s;
- char *text;
-
- text = g_strdup_printf(format, a, b);
- framerender_size_popup_label(text, &s);
- XMoveResizeWindow(ob_display, coords,
- 10, 10, s.width, s.height);
- framerender_popup_label(coords, &s, text);
- g_free(text);
- }
-}
-
-void action_move(union ActionData *data)
-{
- Client *c = data->move.c;
- int x = data->move.x;
- int y = data->move.y;
+ Client *c = data->moveresize.c;
if (!c || !client_normal(c)) return;
- dispatch_move(c, &x, &y);
-
- popup_coords("X: %d Y: %d", ob_cursors.move, x, y, data->move.final);
-
- frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
- client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height,
- TRUE, data->move.final);
-}
-
-void action_resize(union ActionData *data)
-{
- Client *c = data->resize.c;
- Cursor cur;
- int w = data->resize.x;
- int h = data->resize.y;
-
- if (!c || c->shaded || !client_normal(c)) return;
-
- dispatch_resize(c, &w, &h, data->resize.corner);
-
- w -= c->frame->size.left + c->frame->size.right;
- h -= c->frame->size.top + c->frame->size.bottom;
-
- client_configure(c, data->resize.corner, c->area.x, c->area.y, w, h,
- TRUE, data->resize.final);
-
- switch (data->resize.corner) {
- case Corner_TopLeft:
- cur = ob_cursors.br;
- break;
- case Corner_TopRight:
- cur = ob_cursors.bl;
- break;
- case Corner_BottomLeft:
- cur = ob_cursors.tr;
- break;
- case Corner_BottomRight:
- cur = ob_cursors.tl;
- break;
- }
-
- popup_coords("W: %d H: %d", cur, c->logical_size.width,
- c->logical_size.height, data->move.final);
+ moveresize_start(c, data->moveresize.x, data->moveresize.y,
+ data->moveresize.button, data->moveresize.corner);
}
void action_restart(union ActionData *data)
diff --git a/openbox/action.h b/openbox/action.h
index 989b975d..6e0b6c52 100644
--- a/openbox/action.h
+++ b/openbox/action.h
@@ -48,19 +48,12 @@ struct NextPreviousDesktop {
gboolean wrap;
};
-struct Move {
+struct MoveResize {
Client *c;
int x;
int y;
- gboolean final;
-};
-
-struct Resize {
- Client *c;
- int x;
- int y;
- gboolean final;
- Corner corner;
+ guint32 corner; /* prop_atoms.net_wm_moveresize_* */
+ guint button;
};
struct ShowMenu {
@@ -87,8 +80,7 @@ union ActionData {
struct SendToNextPreviousDesktop sendtonextprev;
struct Desktop desktop;
struct NextPreviousDesktop nextprevdesktop;
- struct Move move;
- struct Resize resize;
+ struct MoveResize moveresize;
struct ShowMenu showmenu;
struct CycleWindows cycle;
};
@@ -195,10 +187,8 @@ void action_next_desktop_row(union ActionData *data);
void action_previous_desktop_row(union ActionData *data);
/* ClientAction */
void action_toggle_decorations(union ActionData *data);
-/* Move */
-void action_move(union ActionData *data);
-/* Resize */
-void action_resize(union ActionData *data);
+/* MoveResize */
+void action_moveresize(union ActionData *data);
/* Execute */
void action_restart(union ActionData *data);
/* Any */
diff --git a/openbox/event.c b/openbox/event.c
index 042a76dc..f9191255 100644
--- a/openbox/event.c
+++ b/openbox/event.c
@@ -8,6 +8,7 @@
#include "menu.h"
#include "framerender.h"
#include "focus.h"
+#include "moveresize.h"
#include "stacking.h"
#include "extensions.h"
#include "timer.h"
@@ -359,6 +360,14 @@ static void event_process(XEvent *e)
xerror_set_ignore(FALSE);
}
+ if (moveresize_in_progress)
+ if (e->type == MotionNotify || e->type == ButtonRelease ||
+ e->type == ButtonPress ||
+ e->type == KeyPress || e->type == KeyRelease) {
+ moveresize_event(e);
+ return; /* no dispatch! */
+ }
+
/* user input (action-bound) events */
/*
if (e->type == ButtonPress || e->type == ButtonRelease ||
diff --git a/openbox/moveresize.c b/openbox/moveresize.c
new file mode 100644
index 00000000..c8263179
--- /dev/null
+++ b/openbox/moveresize.c
@@ -0,0 +1,192 @@
+#include "grab.h"
+#include "framerender.h"
+#include "prop.h"
+#include "client.h"
+#include "dispatch.h"
+#include "openbox.h"
+
+#include <X11/Xlib.h>
+#include <glib.h>
+
+gboolean moveresize_in_progress = FALSE;
+static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
+
+static Window coords = None;
+static int start_x, start_y, start_cx, start_cy, start_cw, start_ch;
+static int cur_x, cur_y;
+static Client *client;
+static guint button;
+static guint32 corner;
+static Corner lockcorner;
+
+#define POPUP_X (10)
+#define POPUP_Y (10)
+
+static void popup_coords(char *format, int a, int b)
+{
+ XSetWindowAttributes attrib;
+ Size s;
+ char *text;
+
+ if (coords == None) {
+ attrib.override_redirect = TRUE;
+ coords = XCreateWindow(ob_display, ob_root,
+ 0, 0, 1, 1, 0, render_depth, InputOutput,
+ render_visual, CWOverrideRedirect, &attrib);
+ g_assert(coords != None);
+
+ XMapWindow(ob_display, coords);
+ }
+
+ text = g_strdup_printf(format, a, b);
+ framerender_size_popup_label(text, &s);
+ XMoveResizeWindow(ob_display, coords,
+ POPUP_X, POPUP_Y, s.width, s.height);
+ framerender_popup_label(coords, &s, text);
+ g_free(text);
+}
+
+void moveresize_start(Client *c, int x, int y, guint b, guint32 cnr)
+{
+ Cursor cur;
+
+ g_assert(!moveresize_in_progress);
+
+ client = c;
+ start_cx = c->frame->area.x;
+ start_cy = c->frame->area.y;
+ start_cw = c->area.width;
+ start_ch = c->area.height;
+ start_x = x;
+ start_y = y;
+ button = b;
+ corner = cnr;
+
+ moveresize_in_progress = TRUE;
+ moving = (corner == prop_atoms.net_wm_moveresize_move ||
+ corner == prop_atoms.net_wm_moveresize_move_keyboard);
+
+ if (corner == prop_atoms.net_wm_moveresize_size_topleft)
+ cur = ob_cursors.tl;
+ else if (corner == prop_atoms.net_wm_moveresize_size_top)
+ cur = ob_cursors.tl;
+ else if (corner == prop_atoms.net_wm_moveresize_size_topright)
+ cur = ob_cursors.tr;
+ else if (corner == prop_atoms.net_wm_moveresize_size_right)
+ cur = ob_cursors.tr;
+ else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
+ cur = ob_cursors.br;
+ else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
+ cur = ob_cursors.br;
+ else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
+ cur = ob_cursors.bl;
+ else if (corner == prop_atoms.net_wm_moveresize_size_left)
+ cur = ob_cursors.bl;
+ else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
+ cur = ob_cursors.br;
+ else if (corner == prop_atoms.net_wm_moveresize_move)
+ cur = ob_cursors.move;
+ else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
+ cur = ob_cursors.move;
+ else
+ g_assert_not_reached();
+
+ grab_keyboard(TRUE);
+ grab_pointer(TRUE, cur);
+}
+
+void moveresize_event(XEvent *e)
+{
+ g_assert(moveresize_in_progress);
+
+ if (e->type == MotionNotify) {
+ if (moving) {
+ cur_x = start_cx + e->xmotion.x_root - start_x;
+ cur_y = start_cy + e->xmotion.y_root - start_y;
+
+ dispatch_move(client, &cur_x, &cur_y);
+
+ popup_coords("X: %d Y: %d", cur_x, cur_y);
+
+ /* get where the client should be */
+ frame_frame_gravity(client->frame, &cur_x, &cur_y);
+ client_configure(client, Corner_TopLeft, cur_x, cur_y,
+ start_cw, start_ch, TRUE, FALSE);
+ } else {
+ if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
+ cur_x = start_cw - (e->xmotion.x_root - start_x);
+ cur_y = start_ch - (e->xmotion.y_root - start_y);
+ lockcorner = Corner_BottomRight;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
+ cur_x = start_cw;
+ cur_y = start_ch - (e->xmotion.y_root - start_y);
+ lockcorner = Corner_BottomRight;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
+ cur_x = start_cw + (e->xmotion.x_root - start_x);
+ cur_y = start_ch - (e->xmotion.y_root - start_y);
+ lockcorner = Corner_BottomLeft;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
+ cur_x = start_cw + (e->xmotion.x_root - start_x);
+ cur_y = start_ch;
+ lockcorner = Corner_BottomLeft;
+ } else if (corner ==
+ prop_atoms.net_wm_moveresize_size_bottomright) {
+ cur_x = start_cw + (e->xmotion.x_root - start_x);
+ cur_y = start_ch + (e->xmotion.y_root - start_y);
+ lockcorner = Corner_TopLeft;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
+ cur_x = start_cw;
+ cur_y = start_ch + (e->xmotion.y_root - start_y);
+ lockcorner = Corner_TopLeft;
+ } else if (corner ==
+ prop_atoms.net_wm_moveresize_size_bottomleft) {
+ cur_x = start_cw - (e->xmotion.x_root - start_x);
+ cur_y = start_ch + (e->xmotion.y_root - start_y);
+ lockcorner = Corner_TopRight;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
+ cur_x = start_cw - (e->xmotion.x_root - start_x);
+ cur_y = start_ch;
+ lockcorner = Corner_TopRight;
+ } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
+ cur_x = start_cw + (e->xmotion.x_root - start_x);
+ cur_y = start_ch + (e->xmotion.y_root - start_y);
+ lockcorner = Corner_TopLeft;
+ } else
+ g_assert_not_reached();
+
+ /* dispatch_resize needs the frame size */
+ cur_x += client->frame->size.left + client->frame->size.right;
+ cur_y += client->frame->size.top + client->frame->size.bottom;
+
+ dispatch_resize(client, &cur_x, &cur_y, lockcorner);
+
+ cur_x -= client->frame->size.left + client->frame->size.right;
+ cur_y -= client->frame->size.top + client->frame->size.bottom;
+
+ client_configure(client, lockcorner, client->area.x,
+ client->area.y, cur_x, cur_y, TRUE, FALSE);
+
+ popup_coords("W: %d H: %d", client->logical_size.width,
+ client->logical_size.height);
+ }
+ } else if (e->type == ButtonRelease) {
+ if (e->xbutton.button == button) {
+ grab_keyboard(FALSE);
+ grab_pointer(FALSE, None);
+
+ XDestroyWindow(ob_display, coords);
+ coords = None;
+
+ moveresize_in_progress = FALSE;
+
+ if (moving) {
+ client_configure(client, Corner_TopLeft, cur_x, cur_y,
+ start_cw, start_ch, TRUE, TRUE);
+ } else {
+ client_configure(client, lockcorner, client->area.x,
+ client->area.y, cur_x, cur_y, TRUE, TRUE);
+ }
+ }
+ } else if (e->type == KeyPress) {
+ }
+}
diff --git a/openbox/moveresize.h b/openbox/moveresize.h
new file mode 100644
index 00000000..971ad359
--- /dev/null
+++ b/openbox/moveresize.h
@@ -0,0 +1,14 @@
+#ifndef __moveresize_h
+#define __moveresize_h
+
+#include "client.h"
+
+#include <glib.h>
+
+extern gboolean moveresize_in_progress;
+
+void moveresize_start(Client *c, int x, int y, guint b, guint32 corner);
+
+void moveresize_event(XEvent *e);
+
+#endif
diff --git a/openbox/prop.c b/openbox/prop.c
index bce0426b..cb432ac3 100644
--- a/openbox/prop.c
+++ b/openbox/prop.c
@@ -69,15 +69,18 @@ void prop_startup()
CREATE(net_wm_window_type_dialog, "_NET_WM_WINDOW_TYPE_DIALOG");
CREATE(net_wm_window_type_normal, "_NET_WM_WINDOW_TYPE_NORMAL");
- CREATE(net_wm_moveresize_size_topleft, "_NET_WM_MOVERESIZE_SIZE_TOPLEFT");
- CREATE(net_wm_moveresize_size_topright,
- "_NET_WM_MOVERESIZE_SIZE_TOPRIGHT");
- CREATE(net_wm_moveresize_size_bottomleft,
- "_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT");
- CREATE(net_wm_moveresize_size_bottomright,
- "_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT");
- CREATE(net_wm_moveresize_move, "_NET_WM_MOVERESIZE_MOVE");
-
+ prop_atoms.net_wm_moveresize_size_topleft = 0;
+ prop_atoms.net_wm_moveresize_size_top = 1;
+ prop_atoms.net_wm_moveresize_size_topright = 2;
+ prop_atoms.net_wm_moveresize_size_right = 3;
+ prop_atoms.net_wm_moveresize_size_bottomright = 4;
+ prop_atoms.net_wm_moveresize_size_bottom = 5;
+ prop_atoms.net_wm_moveresize_size_bottomleft = 6;
+ prop_atoms.net_wm_moveresize_size_left = 7;
+ prop_atoms.net_wm_moveresize_move = 8;
+ prop_atoms.net_wm_moveresize_size_keyboard = 9;
+ prop_atoms.net_wm_moveresize_move_keyboard = 10;
+
CREATE(net_wm_action_move, "_NET_WM_ACTION_MOVE");
CREATE(net_wm_action_resize, "_NET_WM_ACTION_RESIZE");
CREATE(net_wm_action_minimize, "_NET_WM_ACTION_MINIMIZE");
diff --git a/openbox/prop.h b/openbox/prop.h
index 8fad09f6..2ed9f559 100644
--- a/openbox/prop.h
+++ b/openbox/prop.h
@@ -73,11 +73,17 @@ typedef struct Atoms {
Atom net_wm_window_type_dialog;
Atom net_wm_window_type_normal;
- Atom net_wm_moveresize_size_topleft;
+ Atom net_wm_moveresize_size_topleft;
+ Atom net_wm_moveresize_size_top;
Atom net_wm_moveresize_size_topright;
- Atom net_wm_moveresize_size_bottomleft;
+ Atom net_wm_moveresize_size_right;
Atom net_wm_moveresize_size_bottomright;
+ Atom net_wm_moveresize_size_bottom;
+ Atom net_wm_moveresize_size_bottomleft;
+ Atom net_wm_moveresize_size_left;
Atom net_wm_moveresize_move;
+ Atom net_wm_moveresize_size_keyboard;
+ Atom net_wm_moveresize_move_keyboard;
Atom net_wm_action_move;
Atom net_wm_action_resize;