From e4d3840f267f95c50299ca725b2dfb1202a09801 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Thu, 4 Apr 2002 13:19:10 +0000
Subject: added startMoving, stopMoving, startResizing and stopResizing and
 fixed bug 528101

---
 src/Window.cc | 229 +++++++++++++++++++++++++++++++---------------------------
 src/Window.hh |  67 +++++++++--------
 2 files changed, 161 insertions(+), 135 deletions(-)

diff --git a/src/Window.cc b/src/Window.cc
index ba18a05..a6689cb 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Window.cc,v 1.37 2002/04/04 11:28:19 fluxgen Exp $
+// $Id: Window.cc,v 1.38 2002/04/04 13:19:10 fluxgen Exp $
 
 //use GNU extensions
 #ifndef	 _GNU_SOURCE
@@ -1495,9 +1495,9 @@ void FluxboxWindow::getWMIconName(void) {
 
 			XFree((char *) text_prop.value);
 		} else
-			client.icon_title = getTitle(); //assign title to icon title
+			client.icon_title = getTitle();
 	} else
-		client.icon_title = getTitle(); //assign title to icon title
+		client.icon_title = getTitle();
 }
 
 
@@ -2035,6 +2035,10 @@ void FluxboxWindow::close(void) {
 void FluxboxWindow::withdraw(void) {
 	visible = false;
 	iconic = false;
+	if (isMoving())
+		stopMoving();
+	if (isResizing())
+		stopResizing();
 
 	XUnmapWindow(display, frame.window);
 
@@ -3295,46 +3299,11 @@ void FluxboxWindow::buttonReleaseEvent(XButtonEvent *re) {
 	if (! validateClient())
 		return;
 
-	if (moving) {
-		moving = false;
-						
-		fluxbox->maskWindowEvents(0, (FluxboxWindow *) 0);
-
-		if (! screen->doOpaqueMove()) {
-			XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
-		 		 frame.move_x, frame.move_y, frame.resize_w,
-			 	 frame.resize_h);
-
-			configure(frame.move_x, frame.move_y, frame.width, frame.height);
-			fluxbox->ungrab();
-		} else
-			configure(frame.x, frame.y, frame.width, frame.height);
-
-		screen->hideGeometry();
-		XUngrabPointer(display, CurrentTime);
-	} else if (resizing) {
-		XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
-			frame.resize_x, frame.resize_y,
-			frame.resize_w, frame.resize_h);
-
-		screen->hideGeometry();
-
-		if (re->window == frame.left_grip)
-			left_fixsize();
-		else
-			right_fixsize();
-
-		resizing = false;
-		configure(frame.resize_x, frame.resize_y,
-				frame.resize_w - screen->getBorderWidth2x(),
-				frame.resize_h - screen->getBorderWidth2x());
-	
-		if (tab)
-			tab->resize();
-			
-		fluxbox->ungrab();
-		XUngrabPointer(display, CurrentTime);
-	} else if (re->window == frame.window) {
+	if (isMoving())
+		stopMoving();		
+	else if (isResizing())
+		stopResizing();
+	else if (re->window == frame.window) {
 		if (re->button == 2 && re->state == Mod1Mask)
 			XUngrabPointer(display, CurrentTime);
 	} else {
@@ -3356,39 +3325,13 @@ void FluxboxWindow::buttonReleaseEvent(XButtonEvent *re) {
 
 
 void FluxboxWindow::motionNotifyEvent(XMotionEvent *me) {
-	Fluxbox *fluxbox = Fluxbox::instance();
 	if ((me->state & Button1Mask) && functions.move &&
 			(frame.title == me->window || frame.label == me->window ||
-			 frame.handle == me->window || frame.window == me->window) && !resizing) {
+			 frame.handle == me->window || frame.window == me->window) && !isResizing()) {
 			 
-		if (! moving) {
-			XGrabPointer(display, me->window, False, Button1MotionMask |
-								ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
-								None, fluxbox->getMoveCursor(), CurrentTime);
-
-			if (windowmenu && windowmenu->isVisible())
-				windowmenu->hide();
-
-			moving = true;
-
-			fluxbox->maskWindowEvents(client.window, this);
-
-			if (! screen->doOpaqueMove()) {
-				fluxbox->grab();
-
-				frame.move_x = frame.x;
-				frame.move_y = frame.y;
-				frame.resize_w = frame.width + screen->getBorderWidth2x();
-				frame.resize_h = ((shaded) ? frame.title_h : frame.height) +
-						screen->getBorderWidth2x();
-
-				screen->showPosition(frame.x, frame.y);
-
-				XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
-				frame.move_x, frame.move_y,
-					frame.resize_w, frame.resize_h);
-			}
-		} else {
+		if (! isMoving()) {
+			startMoving(me->window);			
+		} else {			
 			int dx = me->x_root - frame.grab_x, dy = me->y_root - frame.grab_y;
 
 			dx -= screen->getBorderWidth();
@@ -3429,8 +3372,7 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent *me) {
 
 			if (! screen->doOpaqueMove()) {
 				XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
-						frame.move_x, frame.move_y, frame.resize_w,
-						frame.resize_h);
+						frame.move_x, frame.move_y, frame.resize_w, frame.resize_h);
 
 				frame.move_x = dx;
 				frame.move_y = dy;
@@ -3441,7 +3383,7 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent *me) {
 			} else
 				configure(dx, dy, frame.width, frame.height);
 
-				screen->showPosition(dx, dy);
+			screen->showPosition(dx, dy);
 		}
 	} else if (functions.resize &&
 			(((me->state & Button1Mask) && (me->window == frame.right_grip ||
@@ -3449,35 +3391,8 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent *me) {
 			 me->window == frame.window)) {
 		bool left = (me->window == frame.left_grip);
 
-		if (! resizing) {
-			XGrabPointer(display, me->window, false, ButtonMotionMask |
-				ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None,
-				((left) ? fluxbox->getLowerLeftAngleCursor() :
-				fluxbox->getLowerRightAngleCursor()),
-				CurrentTime);
-
-			resizing = true;
-
-//			fluxbox->grab();
-
-			int gx, gy;
-			frame.grab_x = me->x - screen->getBorderWidth();
-			frame.grab_y = me->y - screen->getBorderWidth2x();
-			frame.resize_x = frame.x;
-			frame.resize_y = frame.y;
-			frame.resize_w = frame.width + screen->getBorderWidth2x();
-			frame.resize_h = frame.height + screen->getBorderWidth2x();
-
-			if (left)
-				left_fixsize(&gx, &gy);
-			else
-				right_fixsize(&gx, &gy);
-
-			screen->showGeometry(gx, gy);
-
-			XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
-				frame.resize_x, frame.resize_y,
-				frame.resize_w, frame.resize_h);
+		if (! resizing) {			
+			startResizing(me, left); 
 		} else if (resizing) {
 			XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
 				frame.resize_x, frame.resize_y,
@@ -3566,6 +3481,110 @@ bool FluxboxWindow::validateClient(void) {
 	return true;
 }
 
+void FluxboxWindow::startMoving(Window win) {
+	moving = true;
+	Fluxbox *fluxbox = Fluxbox::instance();
+	XGrabPointer(display, win, False, Button1MotionMask |
+		ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
+		None, fluxbox->getMoveCursor(), CurrentTime);
+
+	if (windowmenu && windowmenu->isVisible())
+		windowmenu->hide();
+
+	fluxbox->maskWindowEvents(client.window, this);
+
+	if (! screen->doOpaqueMove()) {
+		fluxbox->grab();
+
+		frame.move_x = frame.x;
+		frame.move_y = frame.y;
+		frame.resize_w = frame.width + screen->getBorderWidth2x();
+		frame.resize_h = ((shaded) ? frame.title_h : frame.height) +
+			screen->getBorderWidth2x();
+
+		screen->showPosition(frame.x, frame.y);
+
+		XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
+			frame.move_x, frame.move_y,
+			frame.resize_w, frame.resize_h);
+	}
+}
+
+void FluxboxWindow::stopMoving() {
+	moving = false;
+	Fluxbox *fluxbox = Fluxbox::instance();
+					
+	fluxbox->maskWindowEvents(0, (FluxboxWindow *) 0);
+
+	if (! screen->doOpaqueMove()) {
+		XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
+	 		 frame.move_x, frame.move_y, frame.resize_w,
+		 	 frame.resize_h);
+
+		configure(frame.move_x, frame.move_y, frame.width, frame.height);
+		fluxbox->ungrab();
+	} else
+		configure(frame.x, frame.y, frame.width, frame.height);
+
+	screen->hideGeometry();
+	XUngrabPointer(display, CurrentTime);
+	
+	XSync(display, False); //make sure the redraw is made before we continue
+}
+
+void FluxboxWindow::startResizing(XMotionEvent *me, bool left) {
+	resizing = true;
+	Fluxbox *fluxbox = Fluxbox::instance();
+	XGrabPointer(display, me->window, false, ButtonMotionMask |	ButtonReleaseMask, 
+		GrabModeAsync, GrabModeAsync, None,
+		((left) ? fluxbox->getLowerLeftAngleCursor() : fluxbox->getLowerRightAngleCursor()),
+		CurrentTime);
+
+	int gx, gy;
+	frame.grab_x = me->x - screen->getBorderWidth();
+	frame.grab_y = me->y - screen->getBorderWidth2x();
+	frame.resize_x = frame.x;
+	frame.resize_y = frame.y;
+	frame.resize_w = frame.width + screen->getBorderWidth2x();
+	frame.resize_h = frame.height + screen->getBorderWidth2x();
+
+	if (left)
+		left_fixsize(&gx, &gy);
+	else
+		right_fixsize(&gx, &gy);
+	
+	screen->showGeometry(gx, gy);
+
+	XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
+		frame.resize_x, frame.resize_y,
+		frame.resize_w, frame.resize_h);
+}
+
+void FluxboxWindow::stopResizing(Window win) {
+	resizing = false;
+	
+	XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
+		frame.resize_x, frame.resize_y,
+		frame.resize_w, frame.resize_h);
+
+	screen->hideGeometry();
+
+	if (win == frame.left_grip)
+		left_fixsize();
+	else
+		right_fixsize();
+
+	
+	configure(frame.resize_x, frame.resize_y,
+		frame.resize_w - screen->getBorderWidth2x(),
+		frame.resize_h - screen->getBorderWidth2x());
+	
+	if (tab)
+		tab->resize();
+			
+	Fluxbox::instance()->ungrab();
+	XUngrabPointer(display, CurrentTime);
+}
 
 void FluxboxWindow::restore(void) {
 	XChangeSaveSet(display, client.window, SetModeDelete);
diff --git a/src/Window.hh b/src/Window.hh
index 73612d9..7d61873 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Window.hh,v 1.15 2002/04/03 23:01:04 fluxgen Exp $
+// $Id: Window.hh,v 1.16 2002/04/04 13:19:10 fluxgen Exp $
 
 #ifndef	 WINDOW_HH
 #define	 WINDOW_HH
@@ -120,22 +120,23 @@ public:
 	FluxboxWindow(Window, BScreen * = 0);
 	virtual ~FluxboxWindow(void);
 
-	inline const bool isTransient(void) const { return ((transient) ? true : false); }
-	inline const bool hasTransient(void) const { return ((client.transient) ? true : false); }
-	inline const bool isManaged() const { return managed; }
-	inline const bool isFocused(void) const { return focused; }
-	inline const bool isVisible(void) const { return visible; }
-	inline const bool isIconic(void) const { return iconic; }
-	inline const bool isShaded(void) const { return shaded; }
-	inline const bool isMaximized(void) const { return maximized; }
-	inline const bool isIconifiable(void) const { return functions.iconify; }
-	inline const bool isMaximizable(void) const { return functions.maximize; }
-	inline const bool isResizable(void) const { return functions.resize; }
-	inline const bool isClosable(void) const { return functions.close; }
-	inline const bool isStuck(void) const { return stuck; }
-	inline const bool hasTitlebar(void) const { return decorations.titlebar; }
-	inline const bool hasTab(void) const { return (tab!=0 ? true : false); }
-	static void showError(FluxboxWindow::Error error);
+	inline bool isTransient(void) const { return ((transient) ? true : false); }
+	inline bool hasTransient(void) const { return ((client.transient) ? true : false); }
+	inline bool isManaged() const { return managed; }
+	inline bool isFocused(void) const { return focused; }
+	inline bool isVisible(void) const { return visible; }
+	inline bool isIconic(void) const { return iconic; }
+	inline bool isShaded(void) const { return shaded; }
+	inline bool isMaximized(void) const { return maximized; }
+	inline bool isIconifiable(void) const { return functions.iconify; }
+	inline bool isMaximizable(void) const { return functions.maximize; }
+	inline bool isResizable(void) const { return functions.resize; }
+	inline bool isClosable(void) const { return functions.close; }
+	inline bool isStuck(void) const { return stuck; }
+	inline bool hasTitlebar(void) const { return decorations.titlebar; }
+	inline bool hasTab(void) const { return (tab!=0 ? true : false); }
+	inline bool isMoving(void) const { return moving; }
+	inline bool isResizing(void) const { return resizing; }
 	inline BScreen *getScreen(void) const { return screen; }
 	inline Tab *getTab(void) const { return tab; }
 	inline FluxboxWindow *getTransient(void) const { return client.transient; }
@@ -148,18 +149,18 @@ public:
 
 	inline const std::string &getTitle(void) const { return client.title; }
 	inline const std::string &getIconTitle(void) const { return client.icon_title; }
-	inline const int getXFrame(void) const { return frame.x; }
-	inline const int getYFrame(void) const { return frame.y; }
-	inline const int getXClient(void) const { return client.x; }
-	inline const int getYClient(void) const { return client.y; }
-	inline const unsigned int getWorkspaceNumber(void) const { return workspace_number; }
-	inline const int getWindowNumber(void) const { return window_number; }
-	inline const WinLayer getLayer(void) const { return m_layer; }
-	inline const unsigned int getWidth(void) const { return frame.width; }
-	inline const unsigned int getHeight(void) const { return frame.height; }
-	inline const unsigned int getClientHeight(void) const { return client.height; }
-	inline const unsigned int getClientWidth(void) const { return client.width; }
-	inline const unsigned int getTitleHeight(void) const { return frame.title_h; }
+	inline int getXFrame(void) const { return frame.x; }
+	inline int getYFrame(void) const { return frame.y; }
+	inline int getXClient(void) const { return client.x; }
+	inline int getYClient(void) const { return client.y; }
+	inline unsigned int getWorkspaceNumber(void) const { return workspace_number; }
+	inline int getWindowNumber(void) const { return window_number; }
+	inline WinLayer getLayer(void) const { return m_layer; }
+	inline unsigned int getWidth(void) const { return frame.width; }
+	inline unsigned int getHeight(void) const { return frame.height; }
+	inline unsigned int getClientHeight(void) const { return client.height; }
+	inline unsigned int getClientWidth(void) const { return client.width; }
+	inline unsigned int getTitleHeight(void) const { return frame.title_h; }
 
 	inline void setWindowNumber(int n) { window_number = n; }
 	
@@ -197,6 +198,8 @@ public:
 	void exposeEvent(XExposeEvent *);
 	void configureRequestEvent(XConfigureRequestEvent *);
 
+	static void showError(FluxboxWindow::Error error);
+	
 	#ifdef SHAPE
 	void shapeEvent(XShapeEvent *);
 	#endif // SHAPE
@@ -212,6 +215,7 @@ public:
 	void setGnomeState(int state);
 	inline int getGnomeHints() const { return gnome_hints; }
 	#endif
+	
 private:
 	BImageControl *image_ctrl;
 	
@@ -302,7 +306,10 @@ private:
 	void grabButtons();
 	
 	void createButton(int type, ButtonEventProc, ButtonEventProc, ButtonDrawProc);
-	
+	void startMoving(Window win);
+	void stopMoving();
+	void startResizing(XMotionEvent *me, bool left); 
+	void stopResizing(Window win=0);	
 	#ifdef GNOME
 	
 	void updateGnomeAtoms();
-- 
cgit v0.11.2