replaced ModKey with new key commands StartMoving and StartResizing

This commit is contained in:
markt 2007-10-22 17:45:39 +00:00
parent f72633a0e0
commit c6a2605d76
17 changed files with 169 additions and 151 deletions

View file

@ -1,5 +1,14 @@
(Format: Year/Month/Day)
Changes for 1.0.1:
*07/10/22:
* Replaced modKey with new commands StartMoving and StartResizing (Mark)
- your keys file should be updated automatically
- they must be used with a mouse button, or they won't work
- StartResizing takes one or none of the following arguments:
NearestCorner, Center, TopLeft, TopRight, BottomLeft, BottomRight
Window.cc/hh CurrentWindowCmd.cc/hh FbCommandFactory.cc Screen.cc/hh
fluxbox.cc/hh ScreenResources.cc FbCommands.cc/hh
util/fluxbox-update_configs.cc
*07/10/21:
* Allow decorations bitmask to be specified using '0x' (Mark)
Window.cc

View file

@ -31,4 +31,4 @@ session.colorsPerChannel: 4
session.doubleClickInterval: 250
session.cacheMax: 200
session.imageDither: True
session.configVersion: 3
session.configVersion: 4

View file

@ -7,6 +7,9 @@ OnDesktop Mouse5 :PrevWorkspace
OnToolbar Mouse4 :NextWorkspace
OnToolbar Mouse5 :PrevWorkspace
OnWindow Mod1 Mouse1 :StartMoving
OnWindow Mod1 Mouse3 :StartResizing
Mod1 Tab :NextWindow
Mod1 Shift Tab :PrevWindow
Mod1 F1 :Workspace 1

View file

@ -848,11 +848,6 @@ session.screen0.followModel: <model>
be focused. `Ignore' does nothing, and `Follow' uses the setting in
session.screen0.userFollowModel. Default: Ignore
session.screen0.resizeMode: Bottom|Quadrant|Center
Setting this resource to `Quadrant' makes resizing by using the modkey
grab the corner closest to the mouse pointer instead of the bottom right
corner. `Center' resizes all corners at the same time. Default: Bottom
session.screen0.focusModel: ClickToFocus|MouseFocus
This controls how windows gain focus via the mouse. With `ClickToFocus',
the user must click on the window. With `MouseFocus', windows gain focus
@ -1018,11 +1013,6 @@ session.titlebar.right: Minimize Maximize Close
The icons to place in the titlebar of decorated windows. The available
options are Close, Maximize, MenuIcon, Minimize, Shade, and Stick.
session.modKey: <modifier>
This specifies a modifier to use to drag and resize windows without
clicking on the border or titlebar. For example, Alt + Left click will
move windows, and Alt + Right click will resize. Default: Mod1
................................................................................
@ -1163,7 +1153,6 @@ Special Commands
- SetResourceValue <resourcename> <resource> value
- BindKey <key><value>: <action>
- KeyMode <keymode name> <return key sequence>
- SetModKey <modifier>
Couple of things
~~~~~~~~~~~~~~~~

View file

@ -115,6 +115,26 @@ void GoToTabCmd::real_execute() {
(*it)->focus();
}
void StartMovingCmd::real_execute() {
const XEvent &last = Fluxbox::instance()->lastEvent();
if (last.type == ButtonPress) {
const XButtonEvent &be = last.xbutton;
fbwindow().startMoving(be.x_root, be.y_root);
}
}
void StartResizingCmd::real_execute() {
const XEvent &last = Fluxbox::instance()->lastEvent();
if (last.type == ButtonPress) {
const XButtonEvent &be = last.xbutton;
int x = be.x_root - fbwindow().x()
- fbwindow().frame().window().borderWidth();
int y = be.y_root - fbwindow().y()
- fbwindow().frame().window().borderWidth();
fbwindow().startResizing(x, y, fbwindow().getResizeDirection(x, y, m_mode));
}
}
MoveCmd::MoveCmd(const int step_size_x, const int step_size_y) :
m_step_size_x(step_size_x), m_step_size_y(step_size_y) { }

View file

@ -26,8 +26,7 @@
#define CURRENTWINDOWCMD_HH
#include "Command.hh"
class FluxboxWindow;
#include "Window.hh"
/// helper class for window commands
/// calls real_execute if there's a focused window or a window in button press/release window
@ -131,6 +130,24 @@ private:
const int m_tab_num;
};
// begin moving with mouse
class StartMovingCmd: public WindowHelperCmd {
public:
StartMovingCmd() { }
protected:
void real_execute();
};
// begin resizing with mouse
class StartResizingCmd: public WindowHelperCmd {
public:
explicit StartResizingCmd(FluxboxWindow::ResizeModel mode):m_mode(mode) { }
protected:
void real_execute();
private:
const FluxboxWindow::ResizeModel m_mode;
};
// move cmd, relative position
class MoveCmd: public WindowHelperCmd {
public:

View file

@ -158,7 +158,6 @@ FbCommandFactory::FbCommandFactory() {
"setalpha",
"setenv",
"sethead",
"setmodkey",
"setstyle",
"setworkspacename",
"setworkspacenamedialog",
@ -167,6 +166,8 @@ FbCommandFactory::FbCommandFactory() {
"shade",
"shadewindow",
"showdesktop",
"startmoving",
"startresizing",
"stick",
"stickwindow",
"tab",
@ -235,15 +236,7 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
string value = name.substr(pos + 1);
name = name.substr(0, pos);
return new ExportCmd(name, value);
}
else if (command == "setmodkey") {
string modkey(arguments);
FbTk::StringUtil::removeFirstWhitespace(modkey);
FbTk::StringUtil::removeTrailingWhitespace(modkey);
return new SetModKeyCmd(modkey);
}
else if (command == "commanddialog") // run specified fluxbox command
} else if (command == "commanddialog") // run specified fluxbox command
return new CommandDialogCmd();
else if (command == "bindkey" && trusted)
return new BindKeyCmd(arguments);
@ -307,6 +300,38 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
pat = arguments.c_str() + pos;
return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new SetAlphaCmd(focused, relative, unfocused, un_rel)), pat);
} else if (command == "startmoving")
return new StartMovingCmd();
else if (command == "startresizing") {
FluxboxWindow::ResizeModel mode = FluxboxWindow::DEFAULTRESIZE;
vector<string> tokens;
FbTk::StringUtil::stringtok<vector<string> >(tokens, arguments);
if (!tokens.empty()) {
string arg = FbTk::StringUtil::toLower(tokens[0]);
if (arg == "nearestcorner")
mode = FluxboxWindow::QUADRANTRESIZE;
else if (arg == "nearestedge")
mode = FluxboxWindow::NEARESTEDGERESIZE;
else if (arg == "center")
mode = FluxboxWindow::CENTERRESIZE;
else if (arg == "topleft")
mode = FluxboxWindow::TOPLEFTRESIZE;
else if (arg == "top")
mode = FluxboxWindow::TOPRESIZE;
else if (arg == "topright")
mode = FluxboxWindow::TOPRIGHTRESIZE;
else if (arg == "left")
mode = FluxboxWindow::LEFTRESIZE;
else if (arg == "right")
mode = FluxboxWindow::RIGHTRESIZE;
else if (arg == "bottomleft")
mode = FluxboxWindow::BOTTOMLEFTRESIZE;
else if (arg == "bottom")
mode = FluxboxWindow::BOTTOMRESIZE;
else if (arg == "bottomright")
mode = FluxboxWindow::BOTTOMRIGHTRESIZE;
}
return new StartResizingCmd(mode);
} else if (command == "resize" || command == "resizeto" ||
command == "resizehorizontal" || command == "resizevertical") {
FbTk_istringstream is(arguments.c_str());

View file

@ -169,15 +169,6 @@ int ExecuteCmd::run() {
return pid; // compiler happy -> we are happy ;)
}
SetModKeyCmd::SetModKeyCmd(const string& modkey) : m_modkey(modkey) { }
void SetModKeyCmd::execute() {
Fluxbox::instance()->setModKey(m_modkey.c_str());
Fluxbox::instance()->save_rc();
// TODO: we need a better way to do this ...
Fluxbox::instance()->reconfigure();
}
ExportCmd::ExportCmd(const string& name, const string& value) :
m_name(name), m_value(value) {
}

View file

@ -101,14 +101,6 @@ private:
std::string m_filename;
};
class SetModKeyCmd: public FbTk::Command {
public:
explicit SetModKeyCmd(const std::string& modkey);
void execute();
private:
std::string m_modkey;
};
class KeyModeCmd: public FbTk::Command {
public:
explicit KeyModeCmd(const std::string &arguments);

View file

@ -297,7 +297,6 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm,
decorate_transient(rm, true, scrname+".decorateTransient", altscrname+".DecorateTransient"),
default_deco(rm, "NORMAL", scrname+".defaultDeco", altscrname+".DefaultDeco"),
rootcommand(rm, "", scrname+".rootCommand", altscrname+".RootCommand"),
resize_model(rm, BOTTOMRESIZE, scrname+".resizeMode", altscrname+".ResizeMode"),
tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement", altscrname+".Tab.Placement"),
windowmenufile(rm, "", scrname+".windowMenu", altscrname+".WindowMenu"),
typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay", altscrname+".NoFocusWhileTypingDelay"),

View file

@ -92,14 +92,6 @@ public:
FETCH_ACTIVE_WINDOW ///< put that window to the current workspace
};
/// Different resize modes when resizing a window
enum ResizeModel {
BOTTOMRESIZE = 0, ///< resizes from the bottom right corner
QUADRANTRESIZE, ///< resizes from one quadrant
CENTERRESIZE, ///< resizes from center
DEFAULTRESIZE = BOTTOMRESIZE ///< default resize mode is bottom
};
typedef std::list<FluxboxWindow *> Icons;
@ -142,8 +134,6 @@ public:
FbWinFrame::TabPlacement getTabPlacement() const { return *resource.tab_placement; }
ResizeModel getResizeModel() const { return *resource.resize_model; }
inline unsigned int noFocusWhileTypingDelay() const { return *resource.typing_delay; }
inline FollowModel getFollowModel() const { return *resource.follow_model; }
inline FollowModel getUserFollowModel() const { return *resource.user_follow_model; }
@ -561,7 +551,6 @@ private:
decorate_transient;
FbTk::Resource<std::string> default_deco;
FbTk::Resource<std::string> rootcommand;
FbTk::Resource<ResizeModel> resize_model;
FbTk::Resource<FbWinFrame::TabPlacement> tab_placement;
FbTk::Resource<std::string> windowmenufile;
FbTk::Resource<unsigned int> typing_delay;

View file

@ -58,33 +58,6 @@ void FbTk::Resource<FbTk::MenuTheme::MenuMode>::setFromString(const char *str) {
setDefaultValue();
}
template <>
string FbTk::Resource<BScreen::ResizeModel>::getString() const {
switch (m_value) {
case BScreen::QUADRANTRESIZE:
return string("Quadrant");
case BScreen::BOTTOMRESIZE:
return string("Bottom");
case BScreen::CENTERRESIZE:
return string("Center");
}
return string("Default");
}
template<>
void FbTk::Resource<BScreen::ResizeModel>::
setFromString(char const *strval) {
if (strcasecmp(strval, "Bottom") == 0) {
m_value = BScreen::BOTTOMRESIZE;
} else if (strcasecmp(strval, "Quadrant") == 0) {
m_value = BScreen::QUADRANTRESIZE;
} else if (strcasecmp(strval, "Center") == 0) {
m_value = BScreen::CENTERRESIZE;
} else
m_value = BScreen::DEFAULTRESIZE;
}
template<>
string FbTk::Resource<BScreen::FollowModel>::getString() const {
switch (m_value) {

View file

@ -1039,20 +1039,6 @@ void FluxboxWindow::grabButtons() {
XUngrabButton(display, Button1, Mod1Mask|Mod2Mask|Mod3Mask,
frame().window().window());
unsigned int modkey = Fluxbox::instance()->getModKey();
if (modkey) {
//----grab with "all" modifiers
FbTk::KeyUtil::grabButton(Button1, modkey, frame().window().window(),
ButtonReleaseMask | ButtonMotionMask, frame().theme().moveCursor());
XGrabButton(display, Button2, modkey, frame().window().window(), True,
ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
//---grab with "all" modifiers
FbTk::KeyUtil::grabButton(Button3, modkey, frame().window().window(),
ButtonReleaseMask | ButtonMotionMask);
}
}
@ -2592,8 +2578,7 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) {
// check frame events first
frame().buttonPressEvent(be);
if (be.button == 1 || (be.button == 3 &&
be.state == Fluxbox::instance()->getModKey())) {
if (be.button == 1) {
if (!m_focused) //check focus
focus();
@ -2618,28 +2603,14 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) {
void FluxboxWindow::buttonReleaseEvent(XButtonEvent &re) {
if ((re.button == 1) && (re.state & Fluxbox::instance()->getModKey())
&& !screen().clickRaises()) {
if (!isMoving())
raise();
}
if (isMoving())
stopMoving();
else if (isResizing())
stopResizing();
else if (m_attaching_tab)
attachTo(re.x_root, re.y_root);
else if (re.window == frame().window()) {
if (re.button == 2 && re.state == Fluxbox::instance()->getModKey())
ungrabPointer(CurrentTime);
else
frame().buttonReleaseEvent(re);
} else {
else
frame().buttonReleaseEvent(re);
}
}
@ -2654,9 +2625,8 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
|| frame().handle() == me.window
|| frame().window() == me.window);
if (Fluxbox::instance()->getIgnoreBorder()
&& !(me.state & Fluxbox::instance()->getModKey()) // really should check for exact matches
&& !(isMoving() || isResizing() || m_attaching_tab != 0)) {
if (Fluxbox::instance()->getIgnoreBorder() && m_attaching_tab == 0
&& !(isMoving() || isResizing())) {
int borderw = frame().window().borderWidth();
//!! TODO(tabs): the below test ought to be in FbWinFrame
// if mouse is currently on the window border, ignore it
@ -2787,23 +2757,13 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
if (! resizing) {
int cx = frame().width() / 2;
int cy = frame().height() / 2;
ResizeDirection resize_corner = RIGHTBOTTOM;
if (me.window == frame().gripRight())
resize_corner = RIGHTBOTTOM;
else if (me.window == frame().gripLeft())
resize_corner = LEFTBOTTOM;
else if (screen().getResizeModel() != BScreen::QUADRANTRESIZE) {
if (screen().getResizeModel() == BScreen::CENTERRESIZE)
resize_corner = ALLCORNERS;
else
resize_corner = RIGHTBOTTOM;
} else if (me.x < cx)
resize_corner = (me.y < cy) ? LEFTTOP : LEFTBOTTOM;
else
resize_corner = (me.y < cy) ? RIGHTTOP : RIGHTBOTTOM;
else // dragging border of window, so choose nearest corner
resize_corner = getResizeDirection(me.x, me.y, QUADRANTRESIZE);
// We are grabbing frame window in startResizing
// we need to translate coordinates to it.
@ -3404,6 +3364,31 @@ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
}
FluxboxWindow::ResizeDirection FluxboxWindow::getResizeDirection(int x, int y,
ResizeModel model) {
int cx = frame().width() / 2;
int cy = frame().height() / 2;
if (model == CENTERRESIZE)
return ALLCORNERS;
if (model == NEARESTEDGERESIZE) {
if (abs(cy - abs(y - cy)) > abs(cx - abs(x - cx))) // y is nearest
return (y > cy) ? BOTTOM : TOP;
return (x > cx) ? RIGHT : LEFT;
}
if (model == QUADRANTRESIZE) {
if (x < cx)
return (y < cy) ? LEFTTOP : LEFTBOTTOM;
return (y < cy) ? RIGHTTOP : RIGHTBOTTOM;
}
if (model == TOPLEFTRESIZE) return LEFTTOP;
if (model == TOPRESIZE) return TOP;
if (model == TOPRIGHTRESIZE) return RIGHTTOP;
if (model == LEFTRESIZE) return LEFT;
if (model == RIGHTRESIZE) return RIGHT;
if (model == BOTTOMLEFTRESIZE) return LEFTBOTTOM;
if (model == BOTTOMRESIZE) return BOTTOM;
return RIGHTBOTTOM;
}
void FluxboxWindow::startResizing(int x, int y, ResizeDirection dir) {

View file

@ -137,6 +137,22 @@ public:
DECOR_TAB = DECORM_BORDER|DECORM_MENU|DECORM_TAB
};
/// Different resize modes when resizing a window
enum ResizeModel {
QUADRANTRESIZE, ///< resizes from one quadrant
CENTERRESIZE, ///< resizes from center
NEARESTEDGERESIZE, ///< resizes the nearest edge
TOPLEFTRESIZE, ///< resizes top left corner
TOPRESIZE, ///< resizes top edge
TOPRIGHTRESIZE, ///< resizes top right corner
LEFTRESIZE, ///< resizes left edge
RIGHTRESIZE, ///< resizes right edge
BOTTOMLEFTRESIZE, ///< resizes bottom left corner
BOTTOMRESIZE, ///< resizes bottom edge
BOTTOMRIGHTRESIZE, ///< resizes bottom right corner
DEFAULTRESIZE = BOTTOMRIGHTRESIZE ///< default resize mode
};
/**
* Resize direction while resizing
*/
@ -369,6 +385,8 @@ public:
* @param dir the resize direction
*/
void startResizing(int x, int y, ResizeDirection dir);
/// determine which edge or corner to resize
ResizeDirection getResizeDirection(int x, int y, ResizeModel model);
/// stops the resizing
void stopResizing(bool interrupted = false);

View file

@ -211,7 +211,6 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
m_rc_cache_life(m_resourcemanager, 5, "session.cacheLife", "Session.CacheLife"),
m_rc_cache_max(m_resourcemanager, 200, "session.cacheMax", "Session.CacheMax"),
m_rc_auto_raise_delay(m_resourcemanager, 250, "session.autoRaiseDelay", "Session.AutoRaiseDelay"),
m_rc_mod_key(m_resourcemanager, "Mod1", "session.modKey", "Session.ModKey"),
m_masked_window(0),
m_mousescreen(0),
m_keyscreen(0),
@ -643,7 +642,7 @@ void Fluxbox::setupConfigFiles() {
if (create_init)
FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str());
#define CONFIG_VERSION 3
#define CONFIG_VERSION 4
FbTk::Resource<int> config_version(m_resourcemanager, 0,
"session.configVersion", "Session.ConfigVersion");
if (*config_version < CONFIG_VERSION) {
@ -1707,22 +1706,3 @@ void Fluxbox::updateFrameExtents(FluxboxWindow &win) {
(*it).first->updateFrameExtents(win);
}
}
unsigned int Fluxbox::getModKey() const {
if (!(m_rc_mod_key->c_str()))
return 0;
else
return FbTk::KeyUtil::instance().getModifier(m_rc_mod_key->c_str());
}
void Fluxbox::setModKey(const char* modkeyname) {
if (!modkeyname)
return;
unsigned int modkey = FbTk::KeyUtil::instance().getModifier(modkeyname);
if (modkey > 0) {
m_rc_mod_key = modkeyname;
}
}

View file

@ -135,9 +135,6 @@ public:
unsigned int getCacheMax() const { return *m_rc_cache_max; }
unsigned int getModKey() const;
void setModKey(const char*);
void maskWindowEvents(Window w, FluxboxWindow *bw)
{ m_masked = w; m_masked_window = bw; }
@ -246,7 +243,6 @@ private:
FbTk::Resource<TabsAttachArea> m_rc_tabs_attach_area;
FbTk::Resource<unsigned int> m_rc_cache_life, m_rc_cache_max;
FbTk::Resource<time_t> m_rc_auto_raise_delay;
FbTk::Resource<std::string> m_rc_mod_key;
typedef std::map<Window, WinClient *> WinClientMap;
WinClientMap m_window_search;

View file

@ -182,6 +182,38 @@ int run_updates(int old_version, FbTk::ResourceManager rm) {
new_version = 3;
}
if (old_version < 4) { // move modkey to keys file
string whole_keyfile = read_file(keyfilename);
string new_keyfile = "";
// let's put our new keybindings first, so they're easy to find
new_keyfile += "!mouse actions added by fluxbox-update_configs\n";
// need to match user's resize model
FbTk::Resource<string> rc_mode(rm, "Bottom",
"session.screen0.resizeMode",
"Session.Screen0.ResizeMode");
FbTk::Resource<string> rc_modkey(rm, "Mod1",
"session.modKey",
"Session.ModKey");
new_keyfile += "OnWindow " + *rc_modkey + " Mouse1 :StartMoving\n";
if (strcasecmp((*rc_mode).c_str(), "Quadrant") == 0) {
new_keyfile += "OnWindow " + *rc_modkey +
" Mouse3 :StartResizing NearestCorner\n";
} else if (strcasecmp((*rc_mode).c_str(), "Center") == 0) {
new_keyfile += "OnWindow " + *rc_modkey +
" Mouse3 :StartResizing Center\n";
} else {
new_keyfile += "OnWindow " + *rc_modkey +
"StartResizing BottomRight\n";
}
new_keyfile += "\n"; // just for good looks
new_keyfile += whole_keyfile; // don't forget user's old keybindings
write_file(keyfilename, new_keyfile);
new_version = 4;
}
return new_version;
}