// Screen.cc for Fluxbox Window Manager // Copyright (c) 2001 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) // // Screen.cc for Blackbox - an X11 Window manager // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #include "Screen.hh" #include "fluxbox.hh" #include "Keys.hh" #include "Window.hh" #include "WindowCmd.hh" #include "Workspace.hh" #include "Layer.hh" #include "FocusControl.hh" #include "ScreenPlacement.hh" // menu items #include "FbTk/BoolMenuItem.hh" #include "FbTk/IntMenuItem.hh" #include "FbTk/MenuSeparator.hh" #include "FocusModelMenuItem.hh" #include "FbTk/RadioMenuItem.hh" // menus #include "LayerMenu.hh" #include "MenuCreator.hh" #include "WinClient.hh" #include "FbWinFrame.hh" #include "Strut.hh" #include "FbTk/CommandParser.hh" #include "AtomHandler.hh" #include "HeadArea.hh" #include "RectangleUtil.hh" #include "FbCommands.hh" #ifdef USE_SYSTRAY #include "SystemTray.hh" #endif #include "Debug.hh" #include "FbTk/I18n.hh" #include "FbTk/FbWindow.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/MultLayers.hh" #include "FbTk/LayerItem.hh" #include "FbTk/MacroCommand.hh" #include "FbTk/StringUtil.hh" #include "FbTk/ImageControl.hh" #include "FbTk/EventManager.hh" #include "FbTk/Transparent.hh" #include "FbTk/Select2nd.hh" #include "FbTk/Compose.hh" #include "FbTk/FbString.hh" #include "FbTk/STLUtil.hh" #include "FbTk/KeyUtil.hh" #include "FbTk/Util.hh" #include "FbTk/LuaUtil.hh" //use GNU extensions #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif // _GNU_SOURCE #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H #ifdef USE_SLIT #include "Slit.hh" #include "SlitClient.hh" #else // fill it in class Slit {}; #endif // USE_SLIT #ifdef USE_TOOLBAR #include "Toolbar.hh" #else class Toolbar {}; #endif // USE_TOOLBAR #ifdef STDC_HEADERS #include #endif // STDC_HEADERS #ifdef HAVE_UNISTD_H #include #include #endif // HAVE_UNISTD_H #ifdef HAVE_STDARG_H #include #endif // HAVE_STDARG_H #ifdef TIME_WITH_SYS_TIME #include #include #else // !TIME_WITH_SYS_TIME #ifdef HAVE_SYS_TIME_H #include #else // !HAVE_SYS_TIME_H #include #endif // HAVE_SYS_TIME_H #endif // TIME_WITH_SYS_TIME #include #include #include #ifdef XINERAMA extern "C" { #include } #endif // XINERAMA #if defined(HAVE_RANDR) || defined(HAVE_RANDR1_2) #include #endif // HAVE_RANDR #include #include #include #include #ifdef HAVE_CSTRING #include #else #include #endif using std::cerr; using std::endl; using std::string; using std::make_pair; using std::pair; using std::list; using std::vector; using std::mem_fun; using std::bind2nd; using std::equal_to; using std::hex; using std::dec; static bool running = true; namespace { int anotherWMRunning(Display *display, XErrorEvent *) { _FB_USES_NLS; cerr<<_FB_CONSOLETEXT(Screen, AnotherWMRunning, "BScreen::BScreen: an error occured while querying the X server.\n" " another window manager already running on display ", "Message when another WM is found already active on all screens") < > &cmd): FbTk::RadioMenuItem(label, cmd), m_screen(screen), m_place(place) { setCloseOnClick(false); } bool isSelected() const { return m_screen.getTabPlacement() == m_place; } void click(int button, int time, unsigned int mods) { m_screen.saveTabPlacement(m_place); FbTk::RadioMenuItem::click(button, time, mods); } private: BScreen &m_screen; FbWinFrame::TabPlacement m_place; }; struct TabPlacementString { FbWinFrame::TabPlacement placement; const char* str; }; Atom atom_fbcmd = 0; Atom atom_wm_check = 0; Atom atom_net_desktop = 0; Atom atom_utf8_string = 0; Atom atom_kde_systray = 0; Atom atom_kwm1 = 0; void initAtoms(Display* dpy) { atom_wm_check = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); atom_net_desktop = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False); atom_fbcmd = XInternAtom(dpy, "_FLUXBOX_ACTION", False); atom_utf8_string = XInternAtom(dpy, "UTF8_STRING", False); atom_kde_systray = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False); atom_kwm1 = XInternAtom(dpy, "KWM_DOCKWINDOW", False); } } // end anonymous namespace namespace FbTk { template<> const EnumTraits::Pair EnumTraits::s_map[] = { { "TopLeft", FbWinFrame::TOPLEFT }, { "Top", FbWinFrame::TOP }, { "TopRight", FbWinFrame::TOPRIGHT }, { "BottomLeft", FbWinFrame::BOTTOMLEFT }, { "Bottom", FbWinFrame::BOTTOM }, { "BottomRight", FbWinFrame::BOTTOMRIGHT }, { "LeftBottom", FbWinFrame::LEFTBOTTOM }, { "Left", FbWinFrame::LEFT }, { "LeftTop", FbWinFrame::LEFTTOP }, { "RightBottom", FbWinFrame::RIGHTBOTTOM }, { "Right", FbWinFrame::RIGHT }, { "RightTop", FbWinFrame::RIGHTTOP }, { NULL, FbWinFrame::RIGHTTOP } }; } // end namespace FbTk BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, const string &scrname): workspace_names(rm, std::vector(), scrname + ".workspaceNames", FbTk::VectorTraits(",") ), opaque_move(rm, true, scrname + ".opaqueMove"), full_max(rm, false, scrname+".fullMaximization"), max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), max_disable_move(rm, false, scrname+".maxDisableMove"), max_disable_resize(rm, false, scrname+".maxDisableResize"), workspace_warping(rm, true, scrname+".workspacewarping"), show_window_pos(rm, false, scrname+".showwindowposition"), auto_raise(rm, true, scrname+".autoRaise"), click_raises(rm, true, scrname+".clickRaises"), default_deco(rm, "NORMAL", scrname+".defaultDeco"), tab_placement(rm, FbWinFrame::TOPLEFT, scrname+".tab.placement"), windowmenufile(rm, Fluxbox::instance()->getDefaultDataFilename("windowmenu2"), scrname+".windowMenu"), typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay"), workspaces(rm, 4, scrname+".workspaces"), edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold"), focused_alpha(rm, 255, scrname+".window.focus.alpha"), unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"), menu_alpha(rm, 255, scrname+".menu.alpha"), menu_delay(rm, 200, scrname + ".menuDelay", FbTk::RangedIntTraits(0, 5000)), tab_width(rm, 64, scrname + ".tab.width"), tooltip_delay(rm, 500, scrname + ".tooltipDelay"), allow_remote_actions(rm, false, scrname+".allowRemoteActions"), clientmenu_use_pixmap(rm, true, scrname+".clientMenu.usePixmap"), tabs_use_pixmap(rm, true, scrname+".tabs.usePixmap"), max_over_tabs(rm, false, scrname+".tabs.maxOver"), default_internal_tabs(rm, true /* TODO: autoconf option? */ , scrname+".tabs.intitlebar") { } BScreen::BScreen(FbTk::ResourceManager_base &rm, const string &screenname, int scrn, int num_layers) : m_layermanager(num_layers), m_image_control(0), m_focused_windowtheme(new FbWinFrameTheme(scrn, ".focus", ".Focus")), m_unfocused_windowtheme(new FbWinFrameTheme(scrn, ".unfocus", ".Unfocus")), // the order of windowtheme and winbutton theme is important // because winbutton need to rescale the pixmaps in winbutton theme // after fbwinframe have resized them m_focused_winbutton_theme(new WinButtonTheme(scrn, "", "", *m_focused_windowtheme)), m_unfocused_winbutton_theme(new WinButtonTheme(scrn, ".unfocus", ".Unfocus", *m_unfocused_windowtheme)), m_pressed_winbutton_theme(new WinButtonTheme(scrn, ".pressed", ".Pressed", *m_focused_windowtheme)), m_menutheme(new FbTk::MenuTheme(scrn)), m_root_window(scrn), m_geom_window(new OSDWindow(m_root_window, *this, *m_focused_windowtheme)), m_pos_window(new OSDWindow(m_root_window, *this, *m_focused_windowtheme)), m_tooltip_window(new TooltipWindow(m_root_window, *this, *m_focused_windowtheme)), m_dummy_window(scrn, -1, -1, 1, 1, 0, true, false, CopyFromParent, InputOnly), resource(rm, screenname), m_resource_manager(rm), m_name(screenname), m_focus_control(new FocusControl(*this)), m_placement_strategy(new ScreenPlacement(*this)), m_cycling(false), m_cycle_opts(0), m_xinerama_headinfo(0), m_restart(false), m_shutdown(false) { Fluxbox *fluxbox = Fluxbox::instance(); Display *disp = fluxbox->display(); initAtoms(disp); // TODO fluxgen: check if this is the right place (it was not -lis) // // Create the first one, initXinerama will expand this if needed. m_head_areas.resize(1); m_head_areas[0] = new HeadArea(); initXinerama(); // setup error handler to catch "screen already managed by other wm" XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning); rootWindow().setEventMask(ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask); fluxbox->sync(false); XSetErrorHandler((XErrorHandler) old); managed = running; if (! managed) { delete m_placement_strategy; m_placement_strategy = 0; delete m_focus_control; m_focus_control = 0; return; } // we're going to manage the screen, so now add our pid #ifdef HAVE_GETPID unsigned long bpid = static_cast(getpid()); rootWindow().changeProperty(fluxbox->getFluxboxPidAtom(), XA_CARDINAL, sizeof(pid_t) * 8, PropModeReplace, (unsigned char *) &bpid, 1); #endif // HAVE_GETPID // check if we're the first EWMH compliant window manager on this screen Atom xa_ret_type; int ret_format; unsigned long ret_nitems, ret_bytes_after; unsigned char *ret_prop; if (rootWindow().property(atom_wm_check, 0l, 1l, False, XA_WINDOW, &xa_ret_type, &ret_format, &ret_nitems, &ret_bytes_after, &ret_prop) ) { m_restart = (ret_prop != NULL); XFree(ret_prop); } // setup RANDR for this screens root window #if defined(HAVE_RANDR1_2) int randr_mask = RRScreenChangeNotifyMask; #ifdef RRCrtcChangeNotifyMask randr_mask |= RRCrtcChangeNotifyMask; #endif #ifdef RROutputChangeNotifyMask randr_mask |= RROutputChangeNotifyMask; #endif #ifdef RROutputPropertyNotifyMask randr_mask |= RROutputPropertyNotifyMask; #endif XRRSelectInput(disp, rootWindow().window(), randr_mask); #elif defined(HAVE_RANDR) XRRScreenChangeSelectInput(disp, rootWindow().window(), True); #endif // HAVE_RANDR _FB_USES_NLS; #ifdef DEBUG fprintf(stderr, _FB_CONSOLETEXT(Screen, ManagingScreen, "BScreen::BScreen: managing screen %d " "using visual 0x%lx, depth %d\n", "informational message saying screen number (%d), visual (%lx), and colour depth (%d)").c_str(), screenNumber(), XVisualIDFromVisual(rootWindow().visual()), rootWindow().depth()); #endif // DEBUG FbTk::EventManager *evm = FbTk::EventManager::instance(); evm->add(*this, rootWindow()); Keys *keys = fluxbox->keys(); if (keys) keys->registerWindow(rootWindow().window(), *this, Keys::GLOBAL|Keys::ON_DESKTOP); rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); // setup image cache engine m_image_control.reset(new FbTk::ImageControl(scrn, fluxbox->colorsPerChannel(), *fluxbox->getCacheLifeResource(), *fluxbox->getCacheMaxResource())); imageControl().installRootColormap(); root_colormap_installed = true; m_tracker.join(fluxbox->getCacheLifeResource().modifiedSig(), MemFun(imageControl(), &FbTk::ImageControl::setCacheTimeout)); m_tracker.join(fluxbox->getCacheMaxResource().modifiedSig(), MemFun(imageControl(), &FbTk::ImageControl::setCacheMax)); m_root_theme.reset(new RootTheme(imageControl())); m_root_theme->reconfigTheme(); m_tracker.join(resource.focused_alpha.modifiedSig(), MemFun(*focusedWinFrameTheme(), &FbWinFrameTheme::setAlpha)); focusedWinFrameTheme()->setAlpha(*resource.focused_alpha); m_tracker.join(resource.unfocused_alpha.modifiedSig(), MemFun(*unfocusedWinFrameTheme(), &FbWinFrameTheme::setAlpha)); unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); m_tracker.join(resource.menu_alpha.modifiedSig(), MemFun(*m_menutheme, &FbTk::MenuTheme::setAlpha)); m_menutheme->setAlpha(*resource.menu_alpha); m_tracker.join(resource.menu_delay.modifiedSig(), MemFun(*m_menutheme, &FbTk::MenuTheme::setDelay)); m_menutheme->setDelay(*resource.menu_delay); m_tracker.join(focusedWinFrameTheme()->reconfigSig(), FbTk::MemFun(*this, &BScreen::focusedWinFrameThemeReconfigured)); renderGeomWindow(); renderPosWindow(); m_tooltip_window->setDelay(*resource.tooltip_delay); // setup workspaces and workspace menu int nr_ws = *resource.workspaces; addWorkspace(); // at least one for (int i = 1; i < nr_ws; ++i) { addWorkspace(); } m_current_workspace = m_workspaces_list.front(); m_windowmenu.reset(createMenu("")); m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadWindowMenu))); m_rootmenu.reset(createMenu("")); m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper()); m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadMenu))); m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration, "Configuration", "Title of configuration menu"))); setupConfigmenu(*m_configmenu.get()); // check which desktop we should start on unsigned int first_desktop = 0; if (m_restart) { bool exists; unsigned int ret=static_cast(rootWindow().cardinalProperty(atom_net_desktop, &exists)); if (exists) { if (ret < static_cast(nr_ws)) first_desktop = ret; } } changeWorkspaceID(first_desktop); #ifdef USE_SLIT m_slit.reset(new Slit(*this, *layerManager().getLayer(ResourceLayer::DESKTOP))); #endif // USE_SLIT XFlush(disp); } BScreen::~BScreen() { if (! managed) return; m_configmenu.reset(0); m_toolbar.reset(0); FbTk::EventManager *evm = FbTk::EventManager::instance(); evm->remove(rootWindow()); Keys *keys = Fluxbox::instance()->keys(); if (keys) keys->unregisterWindow(rootWindow().window()); if (m_rootmenu.get() != 0) m_rootmenu->removeAll(); // Since workspacemenu holds client list menus (from workspace) // we need to destroy it before we destroy workspaces m_workspacemenu.reset(0); m_extramenus.clear(); removeWorkspaceNames(); using namespace FbTk::STLUtil; destroyAndClear(m_workspaces_list); destroyAndClear(m_managed_resources); //why not destroyAndClear(m_icon_list); ? //problem with that: a delete FluxboxWindow* calls m_diesig.notify() //which leads to screen.removeWindow() which leads to removeIcon(win) //which would modify the m_icon_list anyways... Icons tmp; tmp = m_icon_list; while(!tmp.empty()) { removeWindow(tmp.back()); tmp.back()->restore(true); delete (tmp.back()); tmp.pop_back(); } if (hasXinerama() && m_xinerama_headinfo) { delete [] m_xinerama_headinfo; } // slit must be destroyed before headAreas (Struts) m_slit.reset(0); m_rootmenu.reset(0); m_workspacemenu.reset(0); m_windowmenu.reset(0); // TODO fluxgen: check if this is the right place for (size_t i = 0; i < m_head_areas.size(); i++) delete m_head_areas[i]; delete m_focus_control; delete m_placement_strategy; } bool BScreen::isRestart() { return Fluxbox::instance()->isStartup() && m_restart; } void BScreen::initWindows() { #ifdef USE_TOOLBAR m_toolbar.reset(new Toolbar(*this, *layerManager().getLayer(::ResourceLayer::NORMAL))); #endif // USE_TOOLBAR unsigned int nchild; Window r, p, *children; Display *disp = FbTk::App::instance()->display(); XQueryTree(disp, rootWindow().window(), &r, &p, &children, &nchild); // preen the window list of all icon windows... for better dockapp support for (unsigned int i = 0; i < nchild; i++) { if (children[i] == None) continue; XWMHints *wmhints = XGetWMHints(disp, children[i]); if (wmhints) { if ((wmhints->flags & IconWindowHint) && (wmhints->icon_window != children[i])) for (unsigned int j = 0; j < nchild; j++) { if (children[j] == wmhints->icon_window) { fbdbg<<"BScreen::initWindows(): children[j] = 0x"<validateWindow(children[i])) { fbdbg<<"BScreen::initWindows(): not valid window = "<searchWindow(transient_for) == 0 && !safety_flag) { // add this window back to the beginning of the list of children children[num_transients] = children[i]; num_transients++; fbdbg<<"BScreen::initWindows(): postpone creation of 0x"<show(); #endif // USE_SLIT } unsigned int BScreen::currentWorkspaceID() const { return m_current_workspace->workspaceID(); } const Strut* BScreen::availableWorkspaceArea(int head) const { if (head > numHeads()) { /* May this ever happen? */ static Strut whole(-1 /* should never be used */, 0, width(), 0, height()); return &whole; } return m_head_areas[head ? head-1 : 0]->availableWorkspaceArea(); } unsigned int BScreen::maxLeft(int head) const { // we ignore strut if we're doing full maximization if (hasXinerama()) return doFullMax() ? getHeadX(head) : getHeadX(head) + availableWorkspaceArea(head)->left(); else return doFullMax() ? 0 : availableWorkspaceArea(head)->left(); } unsigned int BScreen::maxRight(int head) const { // we ignore strut if we're doing full maximization if (hasXinerama()) return doFullMax() ? getHeadX(head) + getHeadWidth(head) : getHeadX(head) + getHeadWidth(head) - availableWorkspaceArea(head)->right(); else return doFullMax() ? width() : width() - availableWorkspaceArea(head)->right(); } unsigned int BScreen::maxTop(int head) const { // we ignore strut if we're doing full maximization if (hasXinerama()) return doFullMax() ? getHeadY(head) : getHeadY(head) + availableWorkspaceArea(head)->top(); else return doFullMax() ? 0 : availableWorkspaceArea(head)->top(); } unsigned int BScreen::maxBottom(int head) const { // we ignore strut if we're doing full maximization if (hasXinerama()) return doFullMax() ? getHeadY(head) + getHeadHeight(head) : getHeadY(head) + getHeadHeight(head) - availableWorkspaceArea(head)->bottom(); else return doFullMax() ? height() : height() - availableWorkspaceArea(head)->bottom(); } void BScreen::focusedWinFrameThemeReconfigured() { renderGeomWindow(); renderPosWindow(); Fluxbox *fluxbox = Fluxbox::instance(); const std::list winlist = focusControl().focusedOrderWinList().clientList(); std::list::const_iterator it = winlist.begin(), it_end = winlist.end(); for (; it != it_end; ++it) fluxbox->updateFrameExtents(*(*it)->fbwindow()); } void BScreen::propertyNotify(Atom atom) { if (allowRemoteActions() && atom == atom_fbcmd) { Atom xa_ret_type; int ret_format; unsigned long ret_nitems, ret_bytes_after; char *str; if (rootWindow().property(atom_fbcmd, 0l, 64l, True, XA_STRING, &xa_ret_type, &ret_format, &ret_nitems, &ret_bytes_after, (unsigned char **)&str) && str) { if (ret_bytes_after) { XFree(str); long len = 64 + (ret_bytes_after + 3)/4; rootWindow().property(atom_fbcmd, 0l, len, True, XA_STRING, &xa_ret_type, &ret_format, &ret_nitems, &ret_bytes_after, (unsigned char **)&str); } static std::auto_ptr > cmd(0); cmd.reset(FbTk::CommandParser::instance().parse(str, false)); if (cmd.get()) { cmd->execute(); } XFree(str); } // TODO: this doesn't belong in FbPixmap } else if (FbTk::FbPixmap::rootwinPropertyNotify(screenNumber(), atom)) m_bg_change_sig.emit(*this); } void BScreen::keyPressEvent(XKeyEvent &ke) { if (Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode, Keys::GLOBAL|Keys::ON_DESKTOP)) // re-grab keyboard, so we don't pass KeyRelease to clients // also for catching invalid keys in the middle of keychains FbTk::EventManager::instance()->grabKeyboard(rootWindow().window()); } void BScreen::keyReleaseEvent(XKeyEvent &ke) { if (m_cycling) { unsigned int state = FbTk::KeyUtil::instance().cleanMods(ke.state); state &= ~FbTk::KeyUtil::instance().keycodeToModmask(ke.keycode); if (state) // still cycling return; m_cycling = false; focusControl().stopCyclingFocus(); } if (!Fluxbox::instance()->keys()->inKeychain()) FbTk::EventManager::instance()->ungrabKeyboard(); } void BScreen::buttonPressEvent(XButtonEvent &be) { if (be.button == 1 && !isRootColormapInstalled()) imageControl().installRootColormap(); Keys *keys = Fluxbox::instance()->keys(); keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP, 0, be.time); } void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) { // get modifiers from event that causes this for focus order cycling XEvent ev = Fluxbox::instance()->lastEvent(); unsigned int mods = 0; if (ev.type == KeyPress) mods = FbTk::KeyUtil::instance().cleanMods(ev.xkey.state); else if (ev.type == ButtonPress) mods = FbTk::KeyUtil::instance().cleanMods(ev.xbutton.state); if (!m_cycling && mods) { m_cycling = true; FbTk::EventManager::instance()->grabKeyboard(rootWindow().window()); } if (mods == 0) // can't stacked cycle unless there is a mod to grab options |= FocusableList::STATIC_ORDER; const FocusableList *win_list = FocusableList::getListFromOptions(*this, options); focusControl().cycleFocus(*win_list, pat, reverse); } FbMenu *BScreen::createMenu(const string &label) { FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); FbMenu *menu = new FbMenu(menuTheme(), imageControl(), *layer); if (!label.empty()) menu->setLabel(label); return menu; } FbMenu *BScreen::createToggleMenu(const string &label) { FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); FbMenu *menu = new ToggleMenu(menuTheme(), imageControl(), *layer); if (!label.empty()) menu->setLabel(label); return menu; } void BScreen::addExtraWindowMenu(const FbTk::FbString &label, const FbTk::RefCount &menu) { menu->disableTitle(); m_extramenus.push_back(make_pair(label, menu)); rereadWindowMenu(); } void BScreen::reconfigure() { // realize the number of workspaces from the init-file const unsigned int nr_ws = *resource.workspaces; while(nr_ws > m_workspaces_list.size()) addWorkspace(); while(nr_ws < m_workspaces_list.size()) removeLastWorkspace(); // and update their names for(size_t i = 0; i < std::min(m_workspaces_list.size(), resource.workspace_names->size()); ++i) m_workspaces_list[i]->setName( resource.workspace_names.get()[i] ); // reconfigure workspaces for_each(m_workspaces_list.begin(), m_workspaces_list.end(), mem_fun(&Workspace::reconfigure)); // reconfigure Icons for_each(m_icon_list.begin(), m_icon_list.end(), mem_fun(&FluxboxWindow::reconfigure)); imageControl().cleanCache(); // notify objects that the screen is reconfigured m_reconfigure_sig.emit(*this); reconfigureTabs(); } void BScreen::reconfigureTabs() { const std::list winlist = focusControl().focusedOrderWinList().clientList(); std::list::const_iterator it = winlist.begin(), it_end = winlist.end(); for (; it != it_end; ++it) (*it)->fbwindow()->applyDecorations(); } void BScreen::updateWorkspaceName(unsigned int w) { Workspace *space = getWorkspace(w); if (space) { resource.workspace_names.get()[w] = space->name(); // XXX use resource.workspace_names.modifiedSig() instead m_workspacenames_sig.emit(*this); Fluxbox::instance()->save_rc(); } } void BScreen::removeWorkspaceNames() { resource.workspace_names->clear(); } void BScreen::addIcon(FluxboxWindow *w) { if (w == 0) return; // make sure we have a unique list if (find(iconList().begin(), iconList().end(), w) != iconList().end()) return; iconList().push_back(w); // notify listeners iconListSig().emit(*this); } void BScreen::removeIcon(FluxboxWindow *w) { if (w == 0) return; Icons::iterator erase_it = remove_if(iconList().begin(), iconList().end(), bind2nd(equal_to(), w)); // no need to send iconlist signal if we didn't // change the iconlist if (erase_it != m_icon_list.end()) { iconList().erase(erase_it); iconListSig().emit(*this); } } void BScreen::removeWindow(FluxboxWindow *win) { fbdbg<<"BScreen::removeWindow("<workspaceNumber()); if (space != 0) space->removeWindow(win, false); } void BScreen::removeClient(WinClient &client) { focusControl().removeClient(client); if (client.fbwindow() && client.fbwindow()->isIconic()) iconListSig().emit(*this); using namespace FbTk; // remove any grouping this is expecting Groupables::iterator erase_it = find_if(m_expecting_groups.begin(), m_expecting_groups.end(), Compose(bind2nd(equal_to(), &client), Select2nd())); if (erase_it != m_expecting_groups.end()) m_expecting_groups.erase(erase_it); // the client could be on icon menu so we update it //!! TODO: check this with the new icon menu // updateIconMenu(); } int BScreen::addWorkspace() { bool save_name = getNameOfWorkspace(m_workspaces_list.size()) == ""; Workspace *wkspc = new Workspace(*this, getNameOfWorkspace(m_workspaces_list.size()), m_workspaces_list.size()); m_workspaces_list.push_back(wkspc); if (save_name) { addWorkspaceName(wkspc->name().c_str()); m_workspacenames_sig.emit(*this); } saveWorkspaces(m_workspaces_list.size()); workspaceCountSig().emit( *this ); return m_workspaces_list.size(); } /// removes last workspace /// @return number of desktops left int BScreen::removeLastWorkspace() { if (m_workspaces_list.size() <= 1) return 0; Workspace *wkspc = m_workspaces_list.back(); if (m_current_workspace->workspaceID() == wkspc->workspaceID()) changeWorkspaceID(m_current_workspace->workspaceID() - 1); wkspc->removeAll(wkspc->workspaceID()-1); Icons::iterator it = iconList().begin(); const Icons::iterator it_end = iconList().end(); for (; it != it_end; ++it) { if ((*it)->workspaceNumber() == wkspc->workspaceID()) (*it)->setWorkspace(wkspc->workspaceID()-1); } m_clientlist_sig.emit(*this); //remove last workspace m_workspaces_list.pop_back(); saveWorkspaces(m_workspaces_list.size()); workspaceCountSig().emit( *this ); // must be deleted after we send notify!! // so we dont get bad pointers somewhere // while processing the notify signal delete wkspc; return m_workspaces_list.size(); } void BScreen::changeWorkspaceID(unsigned int id, bool revert) { if (! m_current_workspace || id >= m_workspaces_list.size() || id == m_current_workspace->workspaceID()) return; /* Ignore all EnterNotify events until the pointer actually moves */ this->focusControl().ignoreAtPointer(); FbTk::App::instance()->sync(false); FluxboxWindow *focused = FocusControl::focusedFbWindow(); if (focused && focused->isMoving() && doOpaqueMove()) // don't reassociate if not opaque moving reassociateWindow(focused, id, true); // set new workspace Workspace *old = currentWorkspace(); m_current_workspace = getWorkspace(id); // we show new workspace first in order to appear faster currentWorkspace()->showAll(); // reassociate all windows that are stuck to the new workspace Workspace::Windows wins = old->windowList(); Workspace::Windows::iterator it = wins.begin(); for (; it != wins.end(); ++it) { if ((*it)->isStuck()) { reassociateWindow(*it, id, true); } } // change workspace ID of stuck iconified windows, too Icons::iterator icon_it = iconList().begin(); for (; icon_it != iconList().end(); ++icon_it) { if ((*icon_it)->isStuck()) (*icon_it)->setWorkspace(id); } if (focused && focused->isMoving() && doOpaqueMove()) focused->focus(); else if (revert) FocusControl::revertFocus(*this); old->hideAll(false); FbTk::App::instance()->sync(false); m_currentworkspace_sig.emit(*this); // do this after atom handlers, so scripts can access new workspace number Fluxbox::instance()->keys()->doAction(FocusIn, 0, 0, Keys::ON_DESKTOP); } void BScreen::sendToWorkspace(unsigned int id, FluxboxWindow *win, bool changeWS) { if (! m_current_workspace || id >= m_workspaces_list.size()) return; if (!win) win = FocusControl::focusedFbWindow(); if (!win || &win->screen() != this || win->isStuck()) return; FbTk::App::instance()->sync(false); windowMenu().hide(); reassociateWindow(win, id, true); // change workspace ? if (changeWS) changeWorkspaceID(id, false); // if the window is on current workspace, show it; else hide it. if (id == currentWorkspace()->workspaceID() && !win->isIconic()) win->show(); else { win->hide(true); FocusControl::revertFocus(*this); } // send all the transients too FluxboxWindow::ClientList::iterator client_it = win->clientList().begin(); FluxboxWindow::ClientList::iterator client_it_end = win->clientList().end(); for (; client_it != client_it_end; ++client_it) { WinClient::TransientList::const_iterator it = (*client_it)->transientList().begin(); WinClient::TransientList::const_iterator it_end = (*client_it)->transientList().end(); for (; it != it_end; ++it) { if ((*it)->fbwindow()) sendToWorkspace(id, (*it)->fbwindow(), false); } } } bool BScreen::isKdeDockapp(Window client) const { //Check and see if client is KDE dock applet. bool iskdedockapp = false; Atom ajunk; int ijunk; unsigned long *data = 0, uljunk; Display *disp = FbTk::App::instance()->display(); // Check if KDE v2.x dock applet if (XGetWindowProperty(disp, client, atom_kde_systray, 0l, 1l, False, XA_WINDOW, &ajunk, &ijunk, &uljunk, &uljunk, (unsigned char **) &data) == Success) { if (data) iskdedockapp = true; XFree((void *) data); data = 0; } // Check if KDE v1.x dock applet if (!iskdedockapp) { if (XGetWindowProperty(disp, client, atom_kwm1, 0l, 1l, False, atom_kwm1, &ajunk, &ijunk, &uljunk, &uljunk, (unsigned char **) &data) == Success && data) { iskdedockapp = (data && data[0] != 0); XFree((void *) data); data = 0; } } return iskdedockapp; } bool BScreen::addKdeDockapp(Window client) { XSelectInput(FbTk::App::instance()->display(), client, StructureNotifyMask); FbTk::EventHandler *evh = 0; FbTk::EventManager *evm = FbTk::EventManager::instance(); AtomHandler* handler = 0; #if USE_SYSTRAY handler = Fluxbox::instance()->getAtomHandler(SystemTray::getNetSystemTrayAtom(screenNumber())); #endif if (handler == 0) { #ifdef USE_SLIT if (slit() != 0 && slit()->acceptKdeDockapp()) slit()->addClient(client); else #endif // USE_SLIT return false; } else { // this handler is a special case // so we call setupClient in it WinClient winclient(client, *this); handler->setupClient(winclient); // we need to save old handler and re-add it later evh = evm->find(client); } if (evh != 0) // re-add handler evm->add(*evh, client); return true; } FluxboxWindow *BScreen::createWindow(Window client) { FbTk::App::instance()->sync(false); if (isKdeDockapp(client) && addKdeDockapp(client)) { return 0; // dont create a FluxboxWindow for this one } WinClient *winclient = new WinClient(client, *this); if (winclient->initial_state == WithdrawnState) { delete winclient; #ifdef USE_SLIT if (slit() && !isKdeDockapp(client)) slit()->addClient(client); #endif // USE_SLIT return 0; } // check if it should be grouped with something else FluxboxWindow *win; WinClient *other; if ((other = findGroupLeft(*winclient)) && (win = other->fbwindow())) { win->attachClient(*winclient); Fluxbox::instance()->attachSignals(*winclient); } else { Fluxbox::instance()->attachSignals(*winclient); if (winclient->fbwindow()) { // may have been set in an atomhandler win = winclient->fbwindow(); Workspace *workspace = getWorkspace(win->workspaceNumber()); if (workspace) workspace->updateClientmenu(); } else { win = new FluxboxWindow(*winclient); if (!win->isManaged()) { delete win; return 0; } } } // add the window to the focus list // always add to front on startup to keep the focus order the same if (win->isFocused() || Fluxbox::instance()->isStartup()) focusControl().addFocusFront(*winclient); else focusControl().addFocusBack(*winclient); // we also need to check if another window expects this window to the left // and if so, then join it. if ((other = findGroupRight(*winclient)) && other->fbwindow() != win) win->attachClient(*other); else if (other) // should never happen win->moveClientRightOf(*other, *winclient); m_clientlist_sig.emit(*this); FbTk::App::instance()->sync(false); return win; } FluxboxWindow *BScreen::createWindow(WinClient &client) { if (isKdeDockapp(client.window()) && addKdeDockapp(client.window())) { return 0; } FluxboxWindow *win = new FluxboxWindow(client); #ifdef SLIT if (win->initialState() == WithdrawnState && slit() != 0) { slit()->addClient(client.window()); } #endif // SLIT if (!win->isManaged()) { delete win; return 0; } win->show(); // don't ask me why, but client doesn't seem to keep focus in new window // and we don't seem to get a FocusIn event from setInputFocus if ((focusControl().focusNew() || FocusControl::focusedWindow() == &client) && win->focus()) FocusControl::setFocusedWindow(&client); m_clientlist_sig.emit(*this); return win; } Strut *BScreen::requestStrut(int head, int left, int right, int top, int bottom) { if (head > numHeads() && head != 1) { // head does not exist (if head == 1, then numHeads() == 0, // which means no xinerama, but there's a head after all head = numHeads(); } int begin = head-1; int end = head; if (head == 0) { // all heads (or no xinerama) begin = 0; end = (numHeads() ? numHeads() : 1); } Strut* next = 0; for (int i = begin; i != end; i++) { next = m_head_areas[i]->requestStrut(i+1, left, right, top, bottom, next); } return next; } void BScreen::clearStrut(Strut *str) { if (str->next()) clearStrut(str->next()); int head = str->head() ? str->head() - 1 : 0; /* The number of heads may have changed, be careful. */ if (head < (numHeads() ? numHeads() : 1)) m_head_areas[head]->clearStrut(str); // str is invalid now } void BScreen::updateAvailableWorkspaceArea() { size_t n = (numHeads() ? numHeads() : 1); bool updated = false; for (size_t i = 0; i < n; i++) { updated = m_head_areas[i]->updateAvailableWorkspaceArea() || updated; } if (updated) m_workspace_area_sig.emit(*this); } void BScreen::addWorkspaceName(const std::string &name) { resource.workspace_names->push_back(name); Workspace *wkspc = getWorkspace(resource.workspace_names->size()-1); if (wkspc) wkspc->setName(name); } string BScreen::getNameOfWorkspace(unsigned int workspace) const { if (workspace < resource.workspace_names->size()) return (*resource.workspace_names)[workspace]; else return ""; } void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, bool ignore_sticky) { if (w == 0) return; if (wkspc_id >= numberOfWorkspaces()) wkspc_id = currentWorkspace()->workspaceID(); if (!w->isIconic() && w->workspaceNumber() == wkspc_id) return; if (w->isIconic()) { removeIcon(w); getWorkspace(wkspc_id)->addWindow(*w); } else if (ignore_sticky || ! w->isStuck()) { // fresh windows have workspaceNumber == -1, which leads to // an invalid workspace (unsigned int) Workspace* ws = getWorkspace(w->workspaceNumber()); if (ws) ws->removeWindow(w, true); getWorkspace(wkspc_id)->addWindow(*w); } } void BScreen::initMenus() { m_workspacemenu = MenuCreator::createMenuType("workspacemenu", screenNumber()); m_tracker.join(Fluxbox::instance()->getMenuResource().modifiedSig(), MemFun(*m_rootmenu->reloadHelper(), &FbTk::AutoReloadHelper::setMainFile)); m_rootmenu->reloadHelper()->setMainFile(*Fluxbox::instance()->getMenuResource()); m_tracker.join(resource.windowmenufile.modifiedSig(), MemFun(*m_windowmenu->reloadHelper(), &FbTk::AutoReloadHelper::setMainFile)); m_windowmenu->reloadHelper()->setMainFile(*resource.windowmenufile); } void BScreen::rereadMenu() { Fluxbox * const fb = Fluxbox::instance(); lua::state &l = fb->lua(); l.checkstack(1); lua::stack_sentry s(l); m_rootmenu->removeAll(); try { l.loadfile(FbTk::StringUtil::expandFilename(*fb->getMenuResource()).c_str()); l.call(0, 1); MenuCreator::createMenu(*m_rootmenu, l, m_rootmenu->reloadHelper()); } catch(std::runtime_error &e) { _FB_USES_NLS; cerr << _FB_CONSOLETEXT(Menu, RootLoad, "Loading root menu failed: ", "Actual error message follows this string") << e.what() << endl; } if (m_rootmenu->numberOfItems() == 0) { _FB_USES_NLS; typedef FbTk::RefCount > RefCmd; const FbTk::CommandParser &parser = FbTk::CommandParser::instance(); m_rootmenu->setLabel(_FB_XTEXT(Menu, DefaultRootMenu, "Fluxbox default menu", "Title of fallback root menu")); RefCmd execute_xterm(parser.parse("exec", "xterm")); RefCmd reconfigure_fb(parser.parse("reconfigure")); RefCmd restart_fb(parser.parse("restart")); RefCmd exit_fb(parser.parse("exit")); m_rootmenu->insert("xterm", execute_xterm); m_rootmenu->insert(_FB_XTEXT(Menu, Reconfigure, "Reconfigure", "Reload Configuration command"), reconfigure_fb); m_rootmenu->insert(_FB_XTEXT(Menu, Restart, "Restart", "Restart command"), restart_fb); m_rootmenu->insert(_FB_XTEXT(Menu, Exit, "Exit", "Exit command"), exit_fb); } } void BScreen::rereadWindowMenu() { lua::state &l = Fluxbox::instance()->lua(); l.checkstack(1); lua::stack_sentry s(l); m_windowmenu->removeAll(); try { l.loadfile(FbTk::StringUtil::expandFilename(resource.windowmenufile).c_str()); l.call(0, 1); MenuCreator::createMenu(*m_windowmenu, l, m_windowmenu->reloadHelper()); } catch(std::runtime_error &e) { _FB_USES_NLS; cerr << _FB_CONSOLETEXT(Menu, WindowLoad, "Loading window menu failed: ", "Actual error message follows this string") << e.what() << endl; } } void BScreen::addConfigMenu(const FbTk::FbString &label, const FbTk::RefCount &menu) { m_configmenu_list.push_back(make_pair(label, menu)); if (m_configmenu.get()) setupConfigmenu(*m_configmenu.get()); } void BScreen::removeConfigMenu(const FbTk::RefCount &menu) { Configmenus::iterator erase_it = find_if(m_configmenu_list.begin(), m_configmenu_list.end(), FbTk::Compose(bind2nd(equal_to >(), menu), FbTk::Select2nd())); if (erase_it != m_configmenu_list.end()) m_configmenu_list.erase(erase_it); if (!isShuttingdown() && m_configmenu.get()) setupConfigmenu(*m_configmenu.get()); } void BScreen::addManagedResource(FbTk::Resource_base *resource) { m_managed_resources.push_back(resource); } int BScreen::getGap(int head, const char type) { return type == 'w' ? getXGap(head) : getYGap(head); } int BScreen::calRelativeSize(int head, int i, char type) { // return floor(i * getGap(head, type) / 100 + 0.5); return FbTk::RelCalcHelper::calPercentageValueOf(i, getGap(head, type)); } int BScreen::calRelativeWidth(int head, int i) { return calRelativeSize(head, i, 'w'); } int BScreen::calRelativeHeight(int head, int i) { return calRelativeSize(head, i, 'h'); } int BScreen::calRelativePosition(int head, int i, char type) { int max = type == 'w' ? maxLeft(head) : maxTop(head); // return floor((i - min) / getGap(head, type) * 100 + 0.5); return FbTk::RelCalcHelper::calPercentageOf((i - max), getGap(head, type)); } // returns a pixel, which is relative to the width of the screen // screen starts from 0, 1000 px width, if i is 10 then it should return 100 int BScreen::calRelativePositionWidth(int head, int i) { return calRelativePosition(head, i, 'w'); } // returns a pixel, which is relative to the height of th escreen // screen starts from 0, 1000 px height, if i is 10 then it should return 100 int BScreen::calRelativePositionHeight(int head, int i) { return calRelativePosition(head, i, 'h'); } int BScreen::calRelativeDimension(int head, int i, char type) { // return floor(i / getGap(head, type) * 100 + 0.5); return FbTk::RelCalcHelper::calPercentageOf(i, getGap(head, type)); } int BScreen::calRelativeDimensionWidth(int head, int i) { return calRelativeDimension(head, i, 'w'); } int BScreen::calRelativeDimensionHeight(int head, int i) { return calRelativeDimension(head, i, 'h'); } float BScreen::getXGap(int head) { return maxRight(head) - maxLeft(head); } float BScreen::getYGap(int head) { return maxBottom(head) - maxTop(head); } void BScreen::setupConfigmenu(FbTk::Menu &menu) { _FB_USES_NLS; menu.removeAll(); FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand(); FbTk::MacroCommand *s_a_reconftabs_macro = new FbTk::MacroCommand(); FbTk::RefCount > saverc_cmd(new FbTk::SimpleCommand( *Fluxbox::instance(), &Fluxbox::save_rc)); FbTk::RefCount > reconf_cmd(FbTk::CommandParser::instance().parse("reconfigure")); FbTk::RefCount > reconftabs_cmd(new FbTk::SimpleCommand( *this, &BScreen::reconfigureTabs)); s_a_reconf_macro->add(saverc_cmd); s_a_reconf_macro->add(reconf_cmd); s_a_reconftabs_macro->add(saverc_cmd); s_a_reconftabs_macro->add(reconftabs_cmd); FbTk::RefCount > save_and_reconfigure(s_a_reconf_macro); FbTk::RefCount > save_and_reconftabs(s_a_reconftabs_macro); // create focus menu // we don't set this to internal menu so will // be deleted toghether with the parent FbTk::FbString focusmenu_label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); FbTk::RefCount focus_menu( createMenu(focusmenu_label) ); #define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) #define _FOCUSITEM(a, b, c, d, e) \ focus_menu->insert(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), focusControl(), \ e, save_and_reconfigure)) _FOCUSITEM(Configmenu, ClickFocus, "Click To Focus", "Click to focus", FocusControl::CLICKFOCUS); _FOCUSITEM(Configmenu, MouseFocus, "Mouse Focus (Keyboard Friendly)", "Mouse Focus (Keyboard Friendly)", FocusControl::MOUSEFOCUS); _FOCUSITEM(Configmenu, StrictMouseFocus, "Mouse Focus (Strict)", "Mouse Focus (Strict)", FocusControl::STRICTMOUSEFOCUS); #undef _FOCUSITEM focus_menu->insert(new FbTk::MenuSeparator()); focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, ClickTabFocus, "ClickTabFocus", "Click tab to focus windows"), focusControl(), FocusControl::CLICKTABFOCUS, save_and_reconfigure)); focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, MouseTabFocus, "MouseTabFocus", "Hover over tab to focus windows"), focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure)); focus_menu->insert(new FbTk::MenuSeparator()); try { focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, "Focus New Windows", "Focus newly created windows"), m_resource_manager.getResource(name() + ".focusNewWindows"), saverc_cmd)); } catch (FbTk::ResourceException & e) { cerr<insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusSameHead, "Keep Head", "Only revert focus on same head"), m_resource_manager.getResource(name() + ".focusSameHead"), saverc_cmd)); } catch (FbTk::ResourceException e) { cerr<updateMenu(); menu.insert(focusmenu_label, focus_menu); // END focus menu // BEGIN maximize menu FbTk::FbString maxmenu_label = _FB_XTEXT(Configmenu, MaxMenu, "Maximize Options", "heading for maximization options"); FbTk::RefCount maxmenu( createMenu(maxmenu_label) ); _BOOLITEM(*maxmenu, Configmenu, FullMax, "Full Maximization", "Maximise over slit, toolbar, etc", resource.full_max, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc, "Ignore Resize Increment", "Maximizing Ignores Resize Increment (e.g. xterm)", resource.max_ignore_inc, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxDisableMove, "Disable Moving", "Don't Allow Moving While Maximized", resource.max_disable_move, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxDisableResize, "Disable Resizing", "Don't Allow Resizing While Maximized", resource.max_disable_resize, saverc_cmd); maxmenu->updateMenu(); menu.insert(maxmenu_label, maxmenu); // END maximize menu // BEGIN tab menu FbTk::FbString tabmenu_label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); FbTk::RefCount tab_menu( createMenu(tabmenu_label) ); FbTk::FbString tabplacement_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); FbTk::RefCount tabplacement_menu( createToggleMenu(tabplacement_label) ); tab_menu->insert(tabplacement_label, tabplacement_menu); _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar, "Tabs in Titlebar", "Tabs in Titlebar", resource.default_internal_tabs, save_and_reconftabs); tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, "Maximize Over", "Maximize over this thing when maximizing"), resource.max_over_tabs, save_and_reconfigure)); tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), resource.tabs_use_pixmap, save_and_reconfigure)); FbTk::MenuItem *tab_width_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth, "External Tab Width", "Width of external-style tabs"), resource.tab_width, 10, 3000, /* silly number */ *tab_menu); tab_width_item->setCommand(save_and_reconftabs); tab_menu->insert(tab_width_item); // menu is 3 wide, 5 down struct PlacementP { const FbTk::FbString label; FbWinFrame::TabPlacement placement; }; static const PlacementP place_menu[] = { { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT}, { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP}, { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT}, { _FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM}, { _FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT}, { _FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP}, { "", FbWinFrame::TOPLEFT}, { "", FbWinFrame::TOPLEFT}, { "", FbWinFrame::TOPLEFT}, { _FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM}, { _FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT}, { _FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP}, { _FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT}, { _FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM}, { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT} }; tabplacement_menu->setMinimumColumns(3); // create items in sub menu for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { const PlacementP& p = place_menu[i]; if (p.label == "") { tabplacement_menu->insert(p.label); tabplacement_menu->setItemEnabled(i, false); } else tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); } tabplacement_menu->updateMenu(); menu.insert(tabmenu_label, tab_menu); #ifdef HAVE_XRENDER if (FbTk::Transparent::haveRender() || FbTk::Transparent::haveComposite()) { FbTk::FbString alphamenu_label = _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"); FbTk::RefCount alpha_menu( createMenu(alphamenu_label) ); if (FbTk::Transparent::haveComposite(true)) { alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure)); } // in order to save system resources, don't save or reconfigure alpha // settings until after the user is done changing them FbTk::RefCount > delayed_save_and_reconf( new FbTk::DelayedCmd(save_and_reconfigure)); FbTk::MenuItem *focused_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", "Transparency level of the focused window"), resource.focused_alpha, 0, 255, *alpha_menu); focused_alpha_item->setCommand(delayed_save_and_reconf); alpha_menu->insert(focused_alpha_item); FbTk::MenuItem *unfocused_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, UnfocusedAlpha, "Unfocused Window Alpha", "Transparency level of unfocused windows"), resource.unfocused_alpha, 0, 255, *alpha_menu); unfocused_alpha_item->setCommand(delayed_save_and_reconf); alpha_menu->insert(unfocused_alpha_item); FbTk::MenuItem *menu_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu"), resource.menu_alpha, 0, 255, *alpha_menu); menu_alpha_item->setCommand(delayed_save_and_reconf); alpha_menu->insert(menu_alpha_item); alpha_menu->updateMenu(); menu.insert(alphamenu_label, alpha_menu); } #endif // HAVE_XRENDER Configmenus::iterator it = m_configmenu_list.begin(); Configmenus::iterator it_end = m_configmenu_list.end(); for (; it != it_end; ++it) menu.insert(it->first, it->second); _BOOLITEM(menu, Configmenu, OpaqueMove, "Opaque Window Moving", "Window Moving with whole window visible (as opposed to outline moving)", resource.opaque_move, saverc_cmd); _BOOLITEM(menu, Configmenu, WorkspaceWarping, "Workspace Warping", "Workspace Warping - dragging windows to the edge and onto the next workspace", resource.workspace_warping, saverc_cmd); #undef _BOOLITEM // finaly update menu menu.updateMenu(); } void BScreen::shutdown() { rootWindow().setEventMask(NoEventMask); FbTk::App::instance()->sync(false); m_shutdown = true; m_focus_control->shutdown(); for_each(m_workspaces_list.begin(), m_workspaces_list.end(), mem_fun(&Workspace::shutdown)); } void BScreen::showPosition(int x, int y) { if (!doShowWindowPos()) return; char buf[256]; sprintf(buf, "X:%5d x Y:%5d", x, y); FbTk::BiDiString label(buf); m_pos_window->showText(label); } void BScreen::hidePosition() { m_pos_window->hide(); } void BScreen::showGeometry(unsigned int gx, unsigned int gy) { if (!doShowWindowPos()) return; char buf[256]; _FB_USES_NLS; sprintf(buf, _FB_XTEXT(Screen, GeometryFormat, "W: %4d x H: %4d", "Format for width and height window, %4d for width, and %4d for height").c_str(), gx, gy); FbTk::BiDiString label(buf); m_geom_window->showText(label); } void BScreen::showTooltip(const FbTk::BiDiString &text) { if (*resource.tooltip_delay >= 0) m_tooltip_window->showText(text); } void BScreen::hideTooltip() { if (*resource.tooltip_delay >= 0) m_tooltip_window->hide(); } void BScreen::hideGeometry() { m_geom_window->hide(); } void BScreen::setLayer(FbTk::LayerItem &item, int layernum) { m_layermanager.moveToLayer(item, layernum); } /** Goes to the workspace "right" of the current */ void BScreen::nextWorkspace(int delta) { changeWorkspaceID( (currentWorkspaceID() + delta) % numberOfWorkspaces()); } /** Goes to the workspace "left" of the current */ void BScreen::prevWorkspace(int delta) { changeWorkspaceID( (static_cast(numberOfWorkspaces()) + currentWorkspaceID() - (delta % numberOfWorkspaces())) % numberOfWorkspaces()); } /** Goes to the workspace "right" of the current */ void BScreen::rightWorkspace(int delta) { if (currentWorkspaceID()+delta < numberOfWorkspaces()) changeWorkspaceID(currentWorkspaceID()+delta); } /** Goes to the workspace "left" of the current */ void BScreen::leftWorkspace(int delta) { if (currentWorkspaceID() >= static_cast(delta)) changeWorkspaceID(currentWorkspaceID()-delta); } void BScreen::renderGeomWindow() { char buf[256]; _FB_USES_NLS; sprintf(buf, _FB_XTEXT(Screen, GeometrySpacing, "W: %04d x H: %04d", "Representative maximum sized text for width and height dialog").c_str(), 0, 0); FbTk::BiDiString label(buf); m_geom_window->resize(label); m_geom_window->reconfigTheme(); } void BScreen::renderPosWindow() { m_pos_window->resize(FbTk::BiDiString("0:00000 x 0:00000")); m_pos_window->reconfigTheme(); } void BScreen::updateSize() { // update xinerama layout initXinerama(); // check if window geometry has changed if (rootWindow().updateGeometry()) { // reset background m_root_theme->reset(); // send resize notify m_resize_sig.emit(*this); m_workspace_area_sig.emit(*this); // move windows out of inactive heads clearHeads(); } } /** * Find the winclient to this window's left * So, we check the leftgroup hint, and see if we know any windows */ WinClient *BScreen::findGroupLeft(WinClient &winclient) { Window w = winclient.getGroupLeftWindow(); if (w == None) return 0; WinClient *have_client = Fluxbox::instance()->searchWindow(w); if (!have_client) { // not found, add it to expecting m_expecting_groups[w] = &winclient; } else if (&have_client->screen() != &winclient.screen()) // something is not consistent return 0; return have_client; } WinClient *BScreen::findGroupRight(WinClient &winclient) { Groupables::iterator it = m_expecting_groups.find(winclient.window()); if (it == m_expecting_groups.end()) return 0; // yay, this'll do. WinClient *other = it->second; m_expecting_groups.erase(it); // don't expect it anymore // forget about it if it isn't the left-most client in the group Window leftwin = other->getGroupLeftWindow(); if (leftwin != None && leftwin != winclient.window()) return 0; return other; } void BScreen::clearXinerama() { fbdbg<<"BScreen::initXinerama(): dont have Xinerama"<display(); if (!XineramaIsActive(display)) { clearXinerama(); return; } fbdbg<<"BScreen::initXinerama(): have Xinerama"<(win.width() / 2); int cy = win.y() + static_cast(win.height() / 2); long dist = -1; int i; for (i = 0; i < m_xinerama_num_heads; ++i) { XineramaHeadInfo& hi = m_xinerama_headinfo[i]; int d = calcSquareDistance(cx, cy, hi.x() + (hi.width() / 2), hi.y() + (hi.height() / 2)); if (dist == -1 || d < dist) { // found a closer head head = i + 1; dist = d; } } } #endif return head; } int BScreen::getCurrHead() const { if (!hasXinerama()) return 0; int root_x = 0, root_y = 0; #ifdef XINERAMA int ignore_i; unsigned int ignore_ui; Window ignore_w; XQueryPointer(FbTk::App::instance()->display(), rootWindow().window(), &ignore_w, &ignore_w, &root_x, &root_y, &ignore_i, &ignore_i, &ignore_ui); #endif // XINERAMA return getHead(root_x, root_y); } int BScreen::getHeadX(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return 0; return m_xinerama_headinfo[head-1].x(); #else return 0; #endif // XINERAMA } int BScreen::getHeadY(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return 0; return m_xinerama_headinfo[head-1].y(); #else return 0; #endif // XINERAMA } int BScreen::getHeadWidth(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return width(); return m_xinerama_headinfo[head-1].width(); #else return width(); #endif // XINERAMA } int BScreen::getHeadHeight(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return height(); return m_xinerama_headinfo[head-1].height(); #else return height(); #endif // XINERAMA } pair BScreen::clampToHead(int head, int x, int y, int w, int h) const { // if there are multiple heads, head=0 is not valid // a better way would be to search the closest head if (head == 0 && numHeads() != 0) head = 1; int hx = getHeadX(head); int hy = getHeadY(head); int hw = getHeadWidth(head); int hh = getHeadHeight(head); x = FbTk::Util::clamp(x, hx, hx + hw - w); y = FbTk::Util::clamp(y, hy, hy + hh - h); return make_pair(x,y); }