From 27b8fe8270c5b7edcddc42134459500b00d47d4b Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 6 Jul 2007 17:49:24 +0000 Subject: prevent MPlayer from overriding the apps file, and use class name by default with remember menu --- src/Remember.cc | 12 ++++++------ src/Window.cc | 53 ++++++++++++++++++++++++++++++++++++++++------------- src/Window.hh | 2 ++ 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/Remember.cc b/src/Remember.cc index c490e51..cfd0d61 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -319,15 +319,15 @@ Application * Remember::add(WinClient &winclient) { Application *app = new Application(false); // by default, we match against the WMClass of a window. - string win_name = p->getProperty(ClientPattern::NAME, winclient); + string win_class = p->getProperty(ClientPattern::CLASS, winclient); // replace special chars like ( ) and [ ] with \( \) and \[ \] - win_name = FbTk::StringUtil::replaceString(win_name, "(", "\\("); - win_name = FbTk::StringUtil::replaceString(win_name, ")", "\\)"); - win_name = FbTk::StringUtil::replaceString(win_name, "[", "\\["); - win_name = FbTk::StringUtil::replaceString(win_name, "]", "\\]"); + win_class = FbTk::StringUtil::replaceString(win_class, "(", "\\("); + win_class = FbTk::StringUtil::replaceString(win_class, ")", "\\)"); + win_class = FbTk::StringUtil::replaceString(win_class, "[", "\\["); + win_class = FbTk::StringUtil::replaceString(win_class, "]", "\\]"); - p->addTerm(win_name, ClientPattern::NAME); + p->addTerm(win_class, ClientPattern::CLASS); m_clients[&winclient] = app; p->addMatch(); m_pats->push_back(make_pair(p, app)); diff --git a/src/Window.cc b/src/Window.cc index eb2f398..74deb9b 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -246,6 +246,7 @@ FluxboxWindow::FluxboxWindow(WinClient &client, FbWinFrameTheme &tm, m_layersig(*this), m_workspacesig(*this), m_themelistener(*this), + m_creation_time(0), moving(false), resizing(false), shaded(false), iconic(false), stuck(false), m_initialized(false), fullscreen(false), maximized(MAX_NONE), @@ -551,6 +552,10 @@ void FluxboxWindow::init() { m_focused = false; } + struct timeval now; + gettimeofday(&now, NULL); + m_creation_time = now.tv_sec; + sendConfigureNotify(); if (m_shaped) @@ -2567,23 +2572,49 @@ void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { if (client == 0 || isIconic()) return; - int cx = frame().x(), cy = frame().y(), ignore = 0; - unsigned int cw = frame().width(), ch = frame().height(); + int old_x = frame().x(), old_y = frame().y(); + unsigned int old_w = frame().width(); + unsigned int old_h = frame().height() - frame().titlebarHeight() + + frame().handleHeight(); + int cx = old_x, cy = old_y, ignore = 0; + unsigned int cw = old_w, ch = old_h; // make sure the new width/height would be ok with all clients, or else they // could try to resize the window back and forth - if (client != m_client && - cr.value_mask & CWWidth && cr.value_mask & CWHeight) { + if (cr.value_mask & CWWidth || cr.value_mask & CWHeight) { + int new_w = (cr.value_mask & CWWidth) ? cr.width : cw; + int new_h = (cr.value_mask & CWHeight) ? cr.height : ch; ClientList::iterator it = clientList().begin(); ClientList::iterator it_end = clientList().end(); for (; it != it_end; ++it) { - if (!m_client->checkSizeHints(cr.width, cr.height)) { + if (*it != client && !(*it)->checkSizeHints(new_w, new_h)) { sendConfigureNotify(); return; } } } +#ifdef REMEMBER + // don't let misbehaving clients (e.g. MPlayer) move/resize their windows + // just after creation if the user has a saved position/size + if (m_creation_time) { + struct timeval now; + gettimeofday(&now, NULL); + + if (now.tv_sec > m_creation_time + 1) + m_creation_time = 0; + else { + if (Remember::instance().isRemembered(*client, + Remember::REM_DIMENSIONS)) + cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); + + if (Remember::instance().isRemembered(*client, + Remember::REM_POSITION)) + cr.value_mask = cr.value_mask & ~(CWX | CWY); + } + } +#endif // REMEMBER + if (cr.value_mask & CWBorderWidth) client->old_bw = cr.border_width; @@ -2603,24 +2634,20 @@ void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { frame().setActiveGravity(client->gravity(), client->old_bw); } - if (cr.value_mask & CWWidth) { + if (cr.value_mask & CWWidth) cw = cr.width; - // we must set this now, or else window grows when height not specified - ch -= (frame().titlebarHeight() + frame().handleHeight()); - } if (cr.value_mask & CWHeight) ch = cr.height; // whether we should send ConfigureNotify to netizens // the request is for client window so we resize the frame to it first - // NOTE: this might not work correctly if client actually requests that size - if (frame().width() != cw || frame().height() != ch) { - if (frame().x() != cx || frame().y() != cy) + if (old_w != cw || old_h != ch) { + if (old_x != cx || old_y != cy) frame().moveResizeForClient(cx, cy, cw, ch); else frame().resizeForClient(cw, ch); - } else if (frame().x() != cx || frame().y() != cy) { + } else if (old_x != cx || old_y != cy) { frame().move(cx, cy); } diff --git a/src/Window.hh b/src/Window.hh index fa5b305..cb32768 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -566,6 +566,8 @@ private: }; ThemeListener m_themelistener; + time_t m_creation_time; + // Window states bool moving, resizing, shaded, iconic, stuck, m_initialized, fullscreen; -- cgit v0.11.2