fluxbox/src/Screen.cc

1838 lines
48 KiB
C++
Raw Normal View History

// Screen.cc for Fluxbox Window Manager
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
//
2001-12-11 20:47:02 +00:00
// Screen.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@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.
2002-02-26 22:40:31 +00:00
// $Id: Screen.cc,v 1.31 2002/02/26 22:40:31 fluxgen Exp $
2001-12-11 20:47:02 +00:00
// stupid macros needed to access some functions in version 2 of the GNU C
// library
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif // HAVE_CONFIG_H
2002-01-27 12:45:32 +00:00
#include "Screen.hh"
2001-12-11 20:47:02 +00:00
#include "i18n.hh"
#include "fluxbox.hh"
#include "Clientmenu.hh"
#include "Icon.hh"
#include "Image.hh"
2002-01-06 11:07:42 +00:00
#include "StringUtil.hh"
2001-12-11 20:47:02 +00:00
#ifdef SLIT
#include "Slit.hh"
#endif // SLIT
#include "Rootmenu.hh"
#include "Toolbar.hh"
#include "Window.hh"
#include "Workspace.hh"
#include "Workspacemenu.hh"
#ifdef STDC_HEADERS
2001-12-11 20:47:02 +00:00
# include <sys/types.h>
#endif // STDC_HEADERS
#ifdef HAVE_CTYPE_H
2001-12-11 20:47:02 +00:00
# include <ctype.h>
#endif // HAVE_CTYPE_H
#ifdef HAVE_DIRENT_H
2001-12-11 20:47:02 +00:00
# include <dirent.h>
#endif // HAVE_DIRENT_H
#ifdef HAVE_LOCALE_H
2001-12-11 20:47:02 +00:00
# include <locale.h>
#endif // HAVE_LOCALE_H
#ifdef HAVE_UNISTD_H
2001-12-11 20:47:02 +00:00
# include <sys/types.h>
# include <unistd.h>
#endif // HAVE_UNISTD_H
#ifdef HAVE_SYS_STAT_H
2001-12-11 20:47:02 +00:00
# include <sys/stat.h>
#endif // HAVE_SYS_STAT_H
#ifdef HAVE_STDARG_H
2001-12-11 20:47:02 +00:00
# include <stdarg.h>
#endif // HAVE_STDARG_H
#ifndef MAXPATHLEN
2001-12-11 20:47:02 +00:00
#define MAXPATHLEN 255
#endif // MAXPATHLEN
#ifndef FONT_ELEMENT_SIZE
#define FONT_ELEMENT_SIZE 50
#endif // FONT_ELEMENT_SIZE
2002-01-27 12:45:32 +00:00
#include <X11/Xatom.h>
#include <X11/keysym.h>
2001-12-11 20:47:02 +00:00
#include <iostream>
2002-01-20 02:17:23 +00:00
#include <memory>
2002-02-08 13:35:20 +00:00
#include <algorithm>
2002-01-20 02:17:23 +00:00
2001-12-11 20:47:02 +00:00
using namespace std;
static Bool running = True;
static int anotherWMRunning(Display *display, XErrorEvent *) {
fprintf(stderr,
I18n::instance()->
getMessage(
#ifdef NLS
ScreenSet, ScreenAnotherWMRunning,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::BScreen: an error occured while querying the X server.\n"
" another window manager already running on display %s.\n"),
DisplayString(display));
running = False;
return(-1);
}
static int dcmp(const void *one, const void *two) {
return (strcmp((*(char **) one), (*(char **) two)));
}
2002-01-20 02:17:23 +00:00
//---------- resource manipulators ---------
template<>
void Resource<Tab::Alignment>::
setFromString(const char *strval) {
m_value = Tab::getTabAlignmentNum(strval);
}
template<>
void Resource<Tab::Placement>::
setFromString(const char *strval) {
m_value = Tab::getTabPlacementNum(strval);
}
template<>
void Resource<Toolbar::Placement>::
setFromString(const char *strval) {
if (strcasecmp(strval, "TopLeft")==0)
m_value = Toolbar::TOPLEFT;
else if (strcasecmp(strval, "BottomLeft")==0)
m_value = Toolbar::BOTTOMLEFT;
else if (strcasecmp(strval, "TopCenter")==0)
m_value = Toolbar::TOPCENTER;
else if (strcasecmp(strval, "BottomCenter")==0)
m_value = Toolbar::BOTTOMCENTER;
else if (strcasecmp(strval, "TopRight")==0)
m_value = Toolbar::TOPRIGHT;
else if (strcasecmp(strval, "BottomRight")==0)
m_value = Toolbar::BOTTOMRIGHT;
else
setDefaultValue();
}
//--------- resource accessors --------------
template<>
string Resource<Tab::Alignment>::
getString() {
return Tab::getTabAlignmentString(m_value);
}
template<>
string Resource<Tab::Placement>::
getString() {
return Tab::getTabPlacementString(m_value);
}
template<>
string Resource<Toolbar::Placement>::
getString() {
switch (m_value) {
case Toolbar::TOPLEFT:
return string("TopLeft");
break;
case Toolbar::BOTTOMLEFT:
return string("BottomLeft");
break;
case Toolbar::TOPCENTER:
return string("TopCenter");
break;
case Toolbar::BOTTOMCENTER:
return string("BottomCenter");
break;
case Toolbar::TOPRIGHT:
return string("TopRight");
break;
case Toolbar::BOTTOMRIGHT:
return string("BottomRight");
break;
}
//default string
return string("BottomCenter");
}
BScreen::ScreenResource::ScreenResource(ResourceManager &rm,
const std::string &scrname, const std::string &altscrname):
toolbar_on_top(rm, false, scrname+".toolbar.onTop", altscrname+".Toolbar.OnTop"),
toolbar_auto_hide(rm, false, scrname+".toolbar.autoHide", altscrname+".Toolbar.AutoHide"),
image_dither(rm, false, scrname+".imageDither", altscrname+".ImageDither"),
opaque_move(rm, false, "session.opaqueMove", "Session.OpaqueMove"),
full_max(rm, true, scrname+".fullMaximization", altscrname+".FullMaximization"),
max_over_slit(rm, true, scrname+".maxOverSlit",altscrname+".MaxOverSlit"),
tab_rotate_vertical(rm, true, scrname+".tab.rotatevertical", altscrname+".Tab.RotateVertical"),
sloppy_window_grouping(rm, true, scrname+".sloppywindowgrouping", altscrname+".SloppyWindowGrouping"),
focus_last(rm, true, scrname+".focusLastWindow", altscrname+".FocusLastWindow"),
focus_new(rm, true, scrname+".focusNewWindows", altscrname+".FocusNewWindows"),
2002-01-20 02:17:23 +00:00
rootcommand(rm, "", scrname+".rootCommand", altscrname+".RootCommand"),
workspaces(rm, 1, scrname+".workspaces", altscrname+".Workspaces"),
toolbar_width_percent(rm, 65, scrname+".toolbar.widthPercent", altscrname+".Toolbar.WidthPercent"),
edge_snap_threshold(rm, 0, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"),
tab_width(rm, 64, scrname+".tab.width", altscrname+".Tab.Width"),
tab_height(rm, 16, scrname+".tab.height", altscrname+".Tab.Height"),
tab_placement(rm, Tab::PTOP, scrname+".tab.placement", altscrname+".Tab.Placement"),
tab_alignment(rm, Tab::ALEFT, scrname+".tab.alignment", altscrname+".Tab.Alignment"),
toolbar_placement(rm, Toolbar::BOTTOMCENTER, scrname+".toolbar.placement", altscrname+".Toolbar.Placement")
{
};
BScreen::BScreen(ResourceManager &rm, Fluxbox *b,
const string &screenname, const string &altscreenname,
int scrn) : ScreenInfo(b, scrn),
2002-02-17 18:56:14 +00:00
#ifdef GNOME
gnome_win(None),
#endif
2002-01-20 02:17:23 +00:00
theme(0),
resource(rm, screenname, altscreenname)
2002-01-10 12:49:15 +00:00
{
2001-12-11 20:47:02 +00:00
fluxbox = b;
event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
2002-01-20 02:17:23 +00:00
SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
2002-02-17 18:56:14 +00:00
ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask;
2001-12-11 20:47:02 +00:00
XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
XSync(getBaseDisplay()->getXDisplay(), False);
XSetErrorHandler((XErrorHandler) old);
managed = running;
if (! managed)
return;
I18n *i18n = I18n::instance();
fprintf(stderr,
i18n->
getMessage(
2002-01-20 02:17:23 +00:00
#ifdef NLS
2001-12-11 20:47:02 +00:00
ScreenSet, ScreenManagingScreen,
2002-01-20 02:17:23 +00:00
#else // !NLS
2001-12-11 20:47:02 +00:00
0, 0,
2002-01-20 02:17:23 +00:00
#endif // NLS
2001-12-11 20:47:02 +00:00
"BScreen::BScreen: managing screen %d "
"using visual 0x%lx, depth %d\n"),
getScreenNumber(), XVisualIDFromVisual(getVisual()),
getDepth());
rootmenu = 0;
2002-01-20 02:17:23 +00:00
#ifdef HAVE_STRFTIME
2001-12-11 20:47:02 +00:00
resource.strftime_format = 0;
2002-01-20 02:17:23 +00:00
#endif // HAVE_STRFTIME
2001-12-11 20:47:02 +00:00
2002-01-20 02:17:23 +00:00
#ifdef HAVE_GETPID
2001-12-11 20:47:02 +00:00
pid_t bpid = getpid();
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
fluxbox->getFluxboxPidAtom(), XA_CARDINAL,
sizeof(pid_t) * 8, PropModeReplace,
(unsigned char *) &bpid, 1);
2002-01-20 02:17:23 +00:00
#endif // HAVE_GETPID
2001-12-11 20:47:02 +00:00
XDefineCursor(getBaseDisplay()->getXDisplay(), getRootWindow(),
2002-01-20 02:17:23 +00:00
fluxbox->getSessionCursor());
2001-12-11 20:47:02 +00:00
image_control =
new BImageControl(fluxbox, this, True, fluxbox->getColorsPerChannel(),
fluxbox->getCacheLife(), fluxbox->getCacheMax());
2001-12-11 20:47:02 +00:00
image_control->installRootColormap();
root_colormap_installed = True;
fluxbox->load_rc(this);
2002-01-20 02:17:23 +00:00
image_control->setDither(*resource.image_dither);
2001-12-14 10:14:37 +00:00
theme = new Theme(getBaseDisplay()->getXDisplay(), getRootWindow(), getColormap(), getScreenNumber(),
2002-01-10 12:49:15 +00:00
image_control, fluxbox->getStyleFilename(), getRootCommand().c_str());
2002-01-11 10:21:44 +00:00
2002-01-20 02:17:23 +00:00
#ifdef GNOME
2002-02-07 14:46:23 +00:00
initGnomeAtoms();
2002-01-20 02:17:23 +00:00
#endif
2001-12-11 20:47:02 +00:00
#ifdef NEWWMSPEC
Atom netwmsupported[] = {
// getBaseDisplay()->getNETWMStateAtom(),
getBaseDisplay()->getNETNumberOfDesktopsAtom(),
getBaseDisplay()->getNETCurrentDesktopAtom(),
getBaseDisplay()->getNETSupportingWMCheckAtom(),
};
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getNETSupportedAtom(), XA_ATOM, 32, PropModeReplace,
(unsigned char *)netwmsupported, (sizeof netwmsupported)/sizeof netwmsupported[0]);
#endif //!NEWWMSPEC
2001-12-11 20:47:02 +00:00
const char *s = i18n->getMessage(
2002-01-20 02:17:23 +00:00
#ifdef NLS
ScreenSet, ScreenPositionLength,
#else // !NLS
0, 0,
#endif // NLS
"0: 0000 x 0: 0000");
2001-12-11 20:47:02 +00:00
int l = strlen(s);
if (i18n->multibyte()) {
XRectangle ink, logical;
XmbTextExtents(theme->getWindowStyle().font.set, s, l, &ink, &logical);
2001-12-11 20:47:02 +00:00
geom_w = logical.width;
geom_h = theme->getWindowStyle().font.set_extents->max_ink_extent.height;
2001-12-11 20:47:02 +00:00
} else {
geom_h = theme->getWindowStyle().font.fontstruct->ascent +
2002-01-20 02:17:23 +00:00
theme->getWindowStyle().font.fontstruct->descent;
2001-12-11 20:47:02 +00:00
geom_w = XTextWidth(theme->getWindowStyle().font.fontstruct, s, l);
2001-12-11 20:47:02 +00:00
}
geom_w += getBevelWidth()*2;
geom_h += getBevelWidth()*2;
XSetWindowAttributes attrib;
unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
attrib.border_pixel = getBorderColor()->getPixel();
attrib.colormap = getColormap();
attrib.save_under = True;
geom_window =
XCreateWindow(getBaseDisplay()->getXDisplay(), getRootWindow(),
0, 0, geom_w, geom_h, theme->getBorderWidth(), getDepth(),
InputOutput, getVisual(), mask, &attrib);
2001-12-11 20:47:02 +00:00
geom_visible = False;
if (theme->getWindowStyle().l_focus.getTexture() & BImage::PARENTRELATIVE) {
if (theme->getWindowStyle().t_focus.getTexture() ==
(BImage::FLAT | BImage::SOLID)) {
2001-12-11 20:47:02 +00:00
geom_pixmap = None;
XSetWindowBackground(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().t_focus.getColor()->getPixel());
2001-12-11 20:47:02 +00:00
} else {
geom_pixmap = image_control->renderImage(geom_w, geom_h,
&theme->getWindowStyle().t_focus);
2001-12-11 20:47:02 +00:00
XSetWindowBackgroundPixmap(getBaseDisplay()->getXDisplay(),
geom_window, geom_pixmap);
}
} else {
if (theme->getWindowStyle().l_focus.getTexture() ==
(BImage::FLAT | BImage::SOLID)) {
2001-12-11 20:47:02 +00:00
geom_pixmap = None;
XSetWindowBackground(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().l_focus.getColor()->getPixel());
2001-12-11 20:47:02 +00:00
} else {
geom_pixmap = image_control->renderImage(geom_w, geom_h,
&theme->getWindowStyle().l_focus);
2001-12-11 20:47:02 +00:00
XSetWindowBackgroundPixmap(getBaseDisplay()->getXDisplay(),
geom_window, geom_pixmap);
}
}
workspacemenu = new Workspacemenu(this);
iconmenu = new Iconmenu(this);
configmenu = new Configmenu(this);
Workspace *wkspc = (Workspace *) 0;
2002-01-20 02:17:23 +00:00
if (*resource.workspaces != 0) {
for (int i = 0; i < *resource.workspaces; ++i) {
2002-02-08 13:35:20 +00:00
wkspc = new Workspace(this, workspacesList.size());
workspacesList.push_back(wkspc);
2001-12-11 20:47:02 +00:00
workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
}
} else {
2002-02-08 13:35:20 +00:00
wkspc = new Workspace(this, workspacesList.size());
workspacesList.push_back(wkspc);
2001-12-11 20:47:02 +00:00
workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
}
workspacemenu->insert(i18n->
getMessage(
#ifdef NLS
IconSet, IconIcons,
#else // !NLS
0, 0,
#endif // NLS
"Icons"),
2001-12-11 20:47:02 +00:00
iconmenu);
workspacemenu->update();
2002-02-08 13:35:20 +00:00
current_workspace = workspacesList.front();
2001-12-11 20:47:02 +00:00
workspacemenu->setItemSelected(2, True);
toolbar = new Toolbar(this);
#ifdef SLIT
2001-12-11 20:47:02 +00:00
slit = new Slit(this);
#endif // SLIT
2001-12-11 20:47:02 +00:00
InitMenu();
raiseWindows(0, 0);
rootmenu->update();
changeWorkspaceID(0);
updateNetizenWorkspaceCount();
2001-12-11 20:47:02 +00:00
int i;
unsigned int nchild;
Window r, p, *children;
XQueryTree(getBaseDisplay()->getXDisplay(), getRootWindow(), &r, &p,
&children, &nchild);
// preen the window list of all icon windows... for better dockapp support
for (i = 0; i < (int) nchild; i++) {
2001-12-11 20:47:02 +00:00
if (children[i] == None) continue;
XWMHints *wmhints = XGetWMHints(getBaseDisplay()->getXDisplay(),
children[i]);
2001-12-11 20:47:02 +00:00
if (wmhints) {
if ((wmhints->flags & IconWindowHint) &&
(wmhints->icon_window != children[i]))
for (int j = 0; j < (int) nchild; j++) {
2001-12-11 20:47:02 +00:00
if (children[j] == wmhints->icon_window) {
children[j] = None;
break;
}
}
2001-12-11 20:47:02 +00:00
XFree(wmhints);
}
}
// manage shown windows
for (i = 0; i < (int) nchild; ++i) {
if (children[i] == None || (! fluxbox->validateWindow(children[i])))
continue;
XWindowAttributes attrib;
if (XGetWindowAttributes(getBaseDisplay()->getXDisplay(), children[i],
&attrib)) {
if (attrib.override_redirect)
continue;
if (attrib.map_state != IsUnmapped) {
2002-02-11 11:52:07 +00:00
FluxboxWindow *win = new FluxboxWindow(children[i], this);
if (!win->isManaged()) {
delete win;
win = 0;
2002-01-18 01:27:46 +00:00
}
2002-02-11 11:52:07 +00:00
2001-12-11 20:47:02 +00:00
if (win) {
XMapRequestEvent mre;
mre.window = children[i];
win->restoreAttributes();
win->mapRequestEvent(&mre);
}
}
}
}
if (! resource.sloppy_focus)
XSetInputFocus(getBaseDisplay()->getXDisplay(), toolbar->getWindowID(),
RevertToParent, CurrentTime);
XFree(children);
XFlush(getBaseDisplay()->getXDisplay());
}
2002-02-08 13:35:20 +00:00
namespace {
template<typename T>
void delete_obj(T * obj) {
delete obj;
}
}
2001-12-11 20:47:02 +00:00
BScreen::~BScreen(void) {
2002-02-17 18:56:14 +00:00
#ifdef GNOME
XDestroyWindow(getBaseDisplay()->getXDisplay(), gnome_win);
#endif
2001-12-11 20:47:02 +00:00
if (! managed) return;
if (geom_pixmap != None)
image_control->removeImage(geom_pixmap);
if (geom_window != None)
XDestroyWindow(getBaseDisplay()->getXDisplay(), geom_window);
removeWorkspaceNames();
2002-02-08 13:35:20 +00:00
std::for_each(
workspacesList.begin(),
workspacesList.end(),
delete_obj<Workspace>);
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
// don't delete items in the rootmenuList?
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
std::for_each(
iconList.begin(),
iconList.end(),
delete_obj<FluxboxWindow>);
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
std::for_each(
netizenList.begin(),
netizenList.end(),
delete_obj<Netizen>);
2001-12-11 20:47:02 +00:00
#ifdef HAVE_STRFTIME
if (resource.strftime_format)
delete [] resource.strftime_format;
#endif // HAVE_STRFTIME
delete rootmenu;
delete workspacemenu;
delete iconmenu;
delete configmenu;
#ifdef SLIT
delete slit;
#endif // SLIT
delete toolbar;
delete image_control;
delete theme;
}
void BScreen::reconfigure(void) {
2002-01-10 12:49:15 +00:00
#ifdef DEBUG
cerr<<__FILE__<<"("<<__LINE__<<"): BScreen::reconfigure"<<endl;
#endif
Fluxbox::instance()->loadRootCommand(this);
theme->setRootCommand(getRootCommand());
2001-12-11 20:47:02 +00:00
theme->load(fluxbox->getStyleFilename());
theme->reconfigure();
I18n *i18n = I18n::instance();
const char *s = i18n->getMessage(
#ifdef NLS
ScreenSet, ScreenPositionLength,
#else // !NLS
0, 0,
#endif // NLS
"0: 0000 x 0: 0000");
int l = strlen(s);
if (i18n->multibyte()) {
XRectangle ink, logical;
XmbTextExtents(theme->getWindowStyle().font.set, s, l, &ink, &logical);
2001-12-11 20:47:02 +00:00
geom_w = logical.width;
geom_h = theme->getWindowStyle().font.set_extents->max_ink_extent.height;
2001-12-11 20:47:02 +00:00
} else {
geom_w = XTextWidth(theme->getWindowStyle().font.fontstruct, s, l);
2001-12-11 20:47:02 +00:00
geom_h = theme->getWindowStyle().font.fontstruct->ascent +
theme->getWindowStyle().font.fontstruct->descent;
2001-12-11 20:47:02 +00:00
}
geom_w += getBevelWidth()*2;
geom_h += getBevelWidth()*2;
Pixmap tmp = geom_pixmap;
if (theme->getWindowStyle().l_focus.getTexture() & BImage::PARENTRELATIVE) {
if (theme->getWindowStyle().t_focus.getTexture() ==
(BImage::FLAT | BImage::SOLID)) {
2001-12-11 20:47:02 +00:00
geom_pixmap = None;
XSetWindowBackground(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().t_focus.getColor()->getPixel());
2001-12-11 20:47:02 +00:00
} else {
geom_pixmap = image_control->renderImage(geom_w, geom_h,
&theme->getWindowStyle().t_focus);
2001-12-11 20:47:02 +00:00
XSetWindowBackgroundPixmap(getBaseDisplay()->getXDisplay(),
geom_window, geom_pixmap);
}
} else {
if (theme->getWindowStyle().l_focus.getTexture() ==
(BImage::FLAT | BImage::SOLID)) {
2001-12-11 20:47:02 +00:00
geom_pixmap = None;
XSetWindowBackground(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().l_focus.getColor()->getPixel());
2001-12-11 20:47:02 +00:00
} else {
geom_pixmap = image_control->renderImage(geom_w, geom_h,
&theme->getWindowStyle().l_focus);
2001-12-11 20:47:02 +00:00
XSetWindowBackgroundPixmap(getBaseDisplay()->getXDisplay(),
geom_window, geom_pixmap);
}
}
if (tmp) image_control->removeImage(tmp);
XSetWindowBorderWidth(getBaseDisplay()->getXDisplay(), geom_window,
theme->getBorderWidth());
XSetWindowBorder(getBaseDisplay()->getXDisplay(), geom_window,
theme->getBorderColor().getPixel());
workspacemenu->reconfigure();
iconmenu->reconfigure();
{
int remember_sub = rootmenu->getCurrentSubmenu();
InitMenu();
raiseWindows(0, 0);
rootmenu->reconfigure();
rootmenu->drawSubmenu(remember_sub);
}
configmenu->reconfigure();
toolbar->reconfigure();
#ifdef SLIT
slit->reconfigure();
#endif // SLIT
2002-02-08 13:35:20 +00:00
Workspaces::iterator wit = workspacesList.begin();
Workspaces::iterator wit_end = workspacesList.end();
for (; wit != wit_end; ++wit) {
(*wit)->reconfigure();
}
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
Icons::iterator iit = iconList.begin();
Icons::iterator iit_end = iconList.end();
for (; iit != iit_end; ++iit) {
if ((*iit)->validateClient())
(*iit)->reconfigure();
}
2001-12-11 20:47:02 +00:00
image_control->timeout();
}
void BScreen::rereadMenu(void) {
InitMenu();
raiseWindows(0, 0);
rootmenu->reconfigure();
}
void BScreen::removeWorkspaceNames(void) {
2002-02-08 13:35:20 +00:00
workspaceNames.erase(workspaceNames.begin(), workspaceNames.end());
2001-12-11 20:47:02 +00:00
}
void BScreen::updateWorkspaceNamesAtom(void) {
#ifdef GNOME
XTextProperty text;
2002-02-08 13:35:20 +00:00
int number_of_desks = workspaceNames.size();
2001-12-11 20:47:02 +00:00
char s[1024];
char *names[number_of_desks];
for (int i = 0; i < number_of_desks; i++) {
sprintf(s, "Desktop %i", i);
names[i] = new char[strlen(s) + 1];
strcpy(names[i], s);
}
if (XStringListToTextProperty(names, number_of_desks, &text)) {
XSetTextProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
&text, getBaseDisplay()->getGnomeWorkspaceNamesAtom());
XFree(text.value);
}
for (int i = 0; i < number_of_desks; i++)
delete names[i];
2002-02-17 18:56:14 +00:00
2001-12-11 20:47:02 +00:00
#endif
}
void BScreen::addIcon(FluxboxWindow *w) {
if (! w) return;
w->setWorkspace(-1);
2002-02-08 13:35:20 +00:00
w->setWindowNumber(iconList.size());
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
iconList.push_back(w);
2001-12-11 20:47:02 +00:00
iconmenu->insert((const char **) w->getIconTitle());
iconmenu->update();
toolbar->addIcon(w);
}
void BScreen::removeIcon(FluxboxWindow *w) {
if (! w) return;
2002-02-20 22:41:13 +00:00
2002-02-17 19:19:05 +00:00
{
Icons::iterator it = iconList.begin();
Icons::iterator it_end = iconList.end();
for (; it != it_end; ++it) {
if (*it == w) {
iconList.erase(it);
break;
}
}
}
2002-02-20 22:41:13 +00:00
2001-12-11 20:47:02 +00:00
iconmenu->remove(w->getWindowNumber());
iconmenu->update();
toolbar->delIcon(w);
2002-02-08 13:35:20 +00:00
Icons::iterator it = iconList.begin();
Icons::iterator it_end = iconList.end();
for (int i = 0; it != it_end; ++it, ++i) {
(*it)->setWindowNumber(i);
}
2001-12-11 20:47:02 +00:00
}
FluxboxWindow *BScreen::getIcon(int index) {
2002-02-08 13:35:20 +00:00
if (index >= 0 && index < iconList.size())
return iconList[index];
2001-12-11 20:47:02 +00:00
return (FluxboxWindow *) 0;
}
int BScreen::addWorkspace(void) {
2002-02-08 13:35:20 +00:00
Workspace *wkspc = new Workspace(this, workspacesList.size());
workspacesList.push_back(wkspc);
2001-12-11 20:47:02 +00:00
workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
wkspc->getWorkspaceID() + 1);
2001-12-11 20:47:02 +00:00
workspacemenu->update();
2002-02-08 13:35:20 +00:00
saveWorkspaces(workspacesList.size());
2001-12-11 20:47:02 +00:00
toolbar->reconfigure();
updateNetizenWorkspaceCount();
2002-02-08 13:35:20 +00:00
return workspacesList.size();
2001-12-11 20:47:02 +00:00
}
int BScreen::removeLastWorkspace(void) {
2002-02-08 13:35:20 +00:00
if (workspacesList.size() > 1) {
Workspace *wkspc = workspacesList.back();
2001-12-11 20:47:02 +00:00
if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
wkspc->removeAll();
workspacemenu->remove(wkspc->getWorkspaceID() + 2);
workspacemenu->update();
2002-02-08 13:35:20 +00:00
workspacesList.erase(workspacesList.begin() + wkspc->getWorkspaceID());
2001-12-11 20:47:02 +00:00
delete wkspc;
toolbar->reconfigure();
updateNetizenWorkspaceCount();
2002-02-08 13:35:20 +00:00
saveWorkspaces(workspacesList.size());
return workspacesList.size();
2001-12-11 20:47:02 +00:00
}
return 0;
}
void BScreen::changeWorkspaceID(int id) {
2002-02-08 13:35:20 +00:00
if (! current_workspace || id >= workspacesList.size() || id < 0)
2001-12-11 20:47:02 +00:00
return;
if (id != current_workspace->getWorkspaceID()) {
2001-12-19 14:30:44 +00:00
XSync(fluxbox->getXDisplay(), True);
2001-12-11 20:47:02 +00:00
current_workspace->hideAll();
workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
False);
if (fluxbox->getFocusedWindow() &&
fluxbox->getFocusedWindow()->getScreen() == this &&
(! fluxbox->getFocusedWindow()->isStuck())) {
current_workspace->setLastFocusedWindow(fluxbox->getFocusedWindow());
fluxbox->setFocusedWindow((FluxboxWindow *) 0);
}
current_workspace = getWorkspace(id);
workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
True);
toolbar->redrawWorkspaceLabel(True);
current_workspace->showAll();
if (*resource.focus_last && current_workspace->getLastFocusedWindow())
2001-12-19 14:30:44 +00:00
current_workspace->getLastFocusedWindow()->setInputFocus();
2001-12-11 20:47:02 +00:00
}
updateNetizenCurrentWorkspace();
}
void BScreen::sendToWorkspace(int id) {
BScreen::sendToWorkspace(id, true);
}
void BScreen::sendToWorkspace(int id, bool changeWS) {
FluxboxWindow *win;
if (! current_workspace || id >= workspacesList.size() || id < 0)
return;
if (id != current_workspace->getWorkspaceID()) {
XSync(fluxbox->getXDisplay(), True);
win = fluxbox->getFocusedWindow();
if (win && win->getScreen() == this &&
(! win->isStuck())) {
if ( win->getTab() ) {
Tab *tab = win->getTab();
tab->disconnect();
tab->setPosition();
}
win->withdraw();
BScreen::reassociateWindow(win, id, True);
if (changeWS) {
BScreen::changeWorkspaceID(id);
win->setInputFocus();
}
}
}
}
2001-12-11 20:47:02 +00:00
void BScreen::addNetizen(Netizen *n) {
2002-02-08 13:35:20 +00:00
netizenList.push_back(n);
2001-12-11 20:47:02 +00:00
n->sendWorkspaceCount();
n->sendCurrentWorkspace();
2002-02-08 13:35:20 +00:00
Workspaces::iterator it = workspacesList.begin();
Workspaces::iterator it_end = workspacesList.end();
for (; it != it_end; ++it) {
for (int i = 0; i < (*it)->getCount(); ++i) {
n->sendWindowAdd((*it)->getWindow(i)->getClientWindow(),
(*it)->getWorkspaceID());
}
2001-12-11 20:47:02 +00:00
}
Window f = ((fluxbox->getFocusedWindow()) ?
fluxbox->getFocusedWindow()->getClientWindow() : None);
n->sendWindowFocus(f);
}
void BScreen::removeNetizen(Window w) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
if ((*it)->getWindowID() == w) {
Netizen *n = *netizenList.erase(it);
2001-12-11 20:47:02 +00:00
delete n;
break;
}
2002-02-08 13:35:20 +00:00
}
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenCurrentWorkspace(void) {
#ifdef NEWWMSPEC
//update _NET_WM_CURRENT_DESKTOP
int workspace = getCurrentWorkspaceID();
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getNETCurrentDesktopAtom(), XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&workspace, 1);
#endif
#ifdef GNOME
//update _WIN_WORKSPACE
int gnome_workspace = getCurrentWorkspaceID();
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getGnomeWorkspaceAtom(), XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&gnome_workspace, 1);
updateGnomeClientList();
#endif
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendCurrentWorkspace();
}
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWorkspaceCount(void) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendWorkspaceCount();
}
#ifdef NEWWMSPEC
//update _NET_WM_NUMBER_OF_DESKTOPS
int numworkspaces = getCount()-1;
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getNETNumberOfDesktopsAtom(), XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&numworkspaces, 1);
#endif
#ifdef GNOME
{
int numworkspaces = getCount();
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getGnomeWorkspaceCountAtom(), XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&numworkspaces, 1);
}
#endif
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWindowFocus(void) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
Window f = ((fluxbox->getFocusedWindow()) ?
fluxbox->getFocusedWindow()->getClientWindow() : None);
for (; it != it_end; ++it) {
(*it)->sendWindowFocus(f);
}
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendWindowAdd(w, p);
}
2002-02-20 22:41:13 +00:00
#ifdef GNOME
updateGnomeClientList();
#endif
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWindowDel(Window w) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendWindowDel(w);
}
2002-02-20 22:41:13 +00:00
#ifdef GNOME
updateGnomeClientList();
#endif
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWindowRaise(Window w) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendWindowRaise(w);
}
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenWindowLower(Window w) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendWindowLower(w);
}
2001-12-11 20:47:02 +00:00
}
void BScreen::updateNetizenConfigNotify(XEvent *e) {
2002-02-08 13:35:20 +00:00
Netizens::iterator it = netizenList.begin();
Netizens::iterator it_end = netizenList.end();
for (; it != it_end; ++it) {
(*it)->sendConfigNotify(e);
}
2001-12-11 20:47:02 +00:00
}
void BScreen::raiseWindows(Window *workspace_stack, int num) {
Window session_stack[(num + workspacesList.size() + rootmenuList.size() + 30)];
int i = 0;
2001-12-11 20:47:02 +00:00
XRaiseWindow(getBaseDisplay()->getXDisplay(), iconmenu->getWindowID());
2001-12-30 12:05:26 +00:00
session_stack[i++] = iconmenu->getWindowID();
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
Workspaces::iterator wit = workspacesList.begin();
Workspaces::iterator wit_end = workspacesList.end();
for (; wit != wit_end; ++wit) {
session_stack[i++] = (*wit)->getMenu()->getWindowID();
}
2001-12-11 20:47:02 +00:00
2001-12-30 12:05:26 +00:00
session_stack[i++] = workspacemenu->getWindowID();
2001-12-11 20:47:02 +00:00
2001-12-30 12:05:26 +00:00
session_stack[i++] = configmenu->getFocusmenu()->getWindowID();
session_stack[i++] = configmenu->getPlacementmenu()->getWindowID();
session_stack[i++] = configmenu->getTabmenu()->getWindowID();
session_stack[i++] = configmenu->getWindowID();
2001-12-11 20:47:02 +00:00
#ifdef SLIT
2001-12-30 12:05:26 +00:00
session_stack[i++] = slit->getMenu()->getDirectionmenu()->getWindowID();
session_stack[i++] = slit->getMenu()->getPlacementmenu()->getWindowID();
session_stack[i++] = slit->getMenu()->getWindowID();
#endif // SLIT
2001-12-11 20:47:02 +00:00
2001-12-30 12:05:26 +00:00
session_stack[i++] =
2001-12-11 20:47:02 +00:00
toolbar->getMenu()->getPlacementmenu()->getWindowID();
2001-12-30 12:05:26 +00:00
session_stack[i++] = toolbar->getMenu()->getWindowID();
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
Rootmenus::iterator rit = rootmenuList.begin();
Rootmenus::iterator rit_end = rootmenuList.end();
for (; rit != rit_end; ++rit) {
session_stack[i++] = (*rit)->getWindowID();
}
2001-12-30 12:05:26 +00:00
session_stack[i++] = rootmenu->getWindowID();
2001-12-11 20:47:02 +00:00
if (toolbar->isOnTop())
2001-12-30 12:05:26 +00:00
session_stack[i++] = toolbar->getWindowID();
2001-12-11 20:47:02 +00:00
#ifdef SLIT
2001-12-11 20:47:02 +00:00
if (slit->isOnTop())
2001-12-30 12:05:26 +00:00
session_stack[i++] = slit->getWindowID();
#endif // SLIT
2001-12-30 12:05:26 +00:00
int k=num;
2001-12-11 20:47:02 +00:00
while (k--)
2001-12-30 12:05:26 +00:00
session_stack[i++] = *(workspace_stack + k);
2001-12-11 20:47:02 +00:00
XRestackWindows(getBaseDisplay()->getXDisplay(), session_stack, i);
}
#ifdef HAVE_STRFTIME
void BScreen::saveStrftimeFormat(char *format) {
if (resource.strftime_format)
delete [] resource.strftime_format;
2002-01-06 11:07:42 +00:00
resource.strftime_format = StringUtil::strdup(format);
2001-12-11 20:47:02 +00:00
}
#endif // HAVE_STRFTIME
void BScreen::addWorkspaceName(char *name) {
2002-02-08 13:35:20 +00:00
workspaceNames.push_back(name);
2001-12-11 20:47:02 +00:00
}
void BScreen::getNameOfWorkspace(int id, char **name) {
2002-02-08 13:35:20 +00:00
if (id >= 0 && id < workspaceNames.size()) {
const char *wkspc_name = workspaceNames[id].c_str();
2001-12-11 20:47:02 +00:00
if (wkspc_name)
2002-01-06 11:07:42 +00:00
*name = StringUtil::strdup(wkspc_name);
2001-12-11 20:47:02 +00:00
} else
*name = 0;
}
void BScreen::reassociateWindow(FluxboxWindow *w, int wkspc_id, Bool ignore_sticky) {
if (! w) return;
if (wkspc_id == -1)
wkspc_id = current_workspace->getWorkspaceID();
if (w->getWorkspaceNumber() == wkspc_id)
return;
if (w->isIconic()) {
removeIcon(w);
getWorkspace(wkspc_id)->addWindow(w);
} else if (ignore_sticky || ! w->isStuck()) {
getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
getWorkspace(wkspc_id)->addWindow(w);
}
}
void BScreen::nextFocus(void) {
Bool have_focused = False;
int focused_window_number = -1;
FluxboxWindow *next;
2002-02-17 18:56:14 +00:00
const int num_windows = getCurrentWorkspace()->getCount();
if (fluxbox->getFocusedWindow()) {
2001-12-11 20:47:02 +00:00
if (fluxbox->getFocusedWindow()->getScreen()->getScreenNumber() ==
getScreenNumber()) {
have_focused = True;
focused_window_number = fluxbox->getFocusedWindow()->getWindowNumber();
}
2002-02-17 18:56:14 +00:00
}
2001-12-11 20:47:02 +00:00
2002-02-17 18:56:14 +00:00
if (num_windows > 1 && have_focused) {
2001-12-11 20:47:02 +00:00
int next_window_number = focused_window_number;
2002-02-17 18:56:14 +00:00
//try to set next window to focus
2001-12-11 20:47:02 +00:00
do {
2002-02-17 18:56:14 +00:00
if ((++next_window_number) >= num_windows)
next_window_number = 0;
2001-12-11 20:47:02 +00:00
next = getCurrentWorkspace()->getWindow(next_window_number);
2002-02-17 18:56:14 +00:00
} while ((!next->setInputFocus()) && next_window_number !=
focused_window_number);
2001-12-11 20:47:02 +00:00
2002-02-17 18:56:14 +00:00
if (next_window_number != focused_window_number) {
next->setInputFocus();
2001-12-11 20:47:02 +00:00
getCurrentWorkspace()->raiseWindow(next);
2002-02-17 18:56:14 +00:00
}
2001-12-11 20:47:02 +00:00
2002-02-17 18:56:14 +00:00
} else if (num_windows >= 1) {
next = current_workspace->getWindow(0);
//don't raise next window if input focus fails
if (next->setInputFocus())
current_workspace->raiseWindow(next);
2001-12-11 20:47:02 +00:00
}
}
void BScreen::prevFocus(void) {
Bool have_focused = False;
int focused_window_number = -1;
FluxboxWindow *prev;
if (fluxbox->getFocusedWindow())
if (fluxbox->getFocusedWindow()->getScreen()->getScreenNumber() ==
getScreenNumber()) {
have_focused = True;
focused_window_number = fluxbox->getFocusedWindow()->getWindowNumber();
}
if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
int prev_window_number = focused_window_number;
do {
if ((--prev_window_number) < 0)
2002-02-17 18:56:14 +00:00
prev_window_number = getCurrentWorkspace()->getCount() - 1;
2001-12-11 20:47:02 +00:00
prev = getCurrentWorkspace()->getWindow(prev_window_number);
} while ((! prev->setInputFocus()) && (prev_window_number !=
focused_window_number));
if (prev_window_number != focused_window_number)
getCurrentWorkspace()->raiseWindow(prev);
} else if (getCurrentWorkspace()->getCount() >= 1) {
prev = current_workspace->getWindow(0);
current_workspace->raiseWindow(prev);
prev->setInputFocus();
}
}
//--------- raiseFocus -----------
// Raise the current focused window
//--------------------------------
void BScreen::raiseFocus(void) {
Bool have_focused = False;
int focused_window_number = -1;
if (fluxbox->getFocusedWindow())
if (fluxbox->getFocusedWindow()->getScreen()->getScreenNumber() ==
getScreenNumber()) {
have_focused = True;
focused_window_number = fluxbox->getFocusedWindow()->getWindowNumber();
}
if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
getWorkspace(fluxbox->getFocusedWindow()->getWorkspaceNumber())->
raiseWindow(fluxbox->getFocusedWindow());
}
void BScreen::InitMenu(void) {
I18n *i18n = I18n::instance();
if (rootmenu) {
2002-02-08 13:35:20 +00:00
rootmenuList.erase(rootmenuList.begin(), rootmenuList.end());
2001-12-11 20:47:02 +00:00
while (rootmenu->getCount())
rootmenu->remove(0);
} else
rootmenu = new Rootmenu(this);
Bool defaultMenu = True;
if (fluxbox->getMenuFilename()) {
2002-01-27 12:45:32 +00:00
ifstream menu_file(fluxbox->getMenuFilename());
if (!menu_file.fail()) {
if (! menu_file.eof()) {
string line;
int row = 0;
while (getline(menu_file, line) && ! menu_file.eof()) {
row++;
2001-12-11 20:47:02 +00:00
if (line[0] != '#') {
2002-01-27 12:45:32 +00:00
string key;
int pos=0;
int err = StringUtil::getStringBetween(key, line.c_str(), '[', ']');
if (key == "begin") {
pos += err;
string label;
err = StringUtil::getStringBetween(label, line.c_str()+pos, '(', ')');
if (err>0) {
rootmenu->setLabel(label.c_str());
defaultMenu = parseMenuFile(menu_file, rootmenu, row);
} else
cerr<<"Error in menufile. Line("<<row<<")"<<endl;
2001-12-11 20:47:02 +00:00
break;
}
}
}
} else {
fprintf(stderr,
i18n->getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
2001-12-11 20:47:02 +00:00
ScreenSet, ScreenEmptyMenuFile,
2002-01-27 12:45:32 +00:00
#else // !NLS
2001-12-11 20:47:02 +00:00
0, 0,
2002-01-27 12:45:32 +00:00
#endif // NLS
2001-12-11 20:47:02 +00:00
"%s: Empty menu file"),
fluxbox->getMenuFilename());
}
} else
perror(fluxbox->getMenuFilename());
}
if (defaultMenu) {
rootmenu->setInternalMenu();
rootmenu->insert(i18n->getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, Screenxterm,
#else // !NLS
0, 0,
#endif // NLS
"xterm"),
BScreen::EXECUTE,
i18n->getMessage(
#ifdef NLS
ScreenSet, Screenxterm,
#else // !NLS
0, 0,
#endif // NLS
"xterm"));
2001-12-11 20:47:02 +00:00
rootmenu->insert(i18n->getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, ScreenRestart,
#else // !NLS
0, 0,
#endif // NLS
2001-12-11 20:47:02 +00:00
"Restart"),
2002-01-11 10:21:44 +00:00
BScreen::RESTART);
2001-12-11 20:47:02 +00:00
rootmenu->insert(i18n->getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, ScreenExit,
#else // !NLS
0, 0,
#endif // NLS
"Exit"),
2002-01-11 10:21:44 +00:00
BScreen::EXIT);
2001-12-11 20:47:02 +00:00
} else
fluxbox->saveMenuFilename(fluxbox->getMenuFilename());
}
2002-01-27 12:45:32 +00:00
// looks through a menufile and adds correct items to the root-menu.
Bool BScreen::parseMenuFile(ifstream &file, Rootmenu *menu, int &row) {
string line;
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
while (! file.eof()) {
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
if (getline(file, line)) {
row++;
2001-12-11 20:47:02 +00:00
if (line[0] != '#') {
2002-01-27 12:45:32 +00:00
int parse_pos = 0, err = 0;
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
std::string str_key, str_label, str_cmd;
err = StringUtil::getStringBetween(str_key, line.c_str(), '[', ']');
if (err > 0 ) {
parse_pos += err;
err = StringUtil::getStringBetween(str_label, line.c_str() + parse_pos, '(', ')');
if (err>0) {
parse_pos += err;
StringUtil::getStringBetween(str_cmd, line.c_str() + parse_pos, '{', '}');
2001-12-11 20:47:02 +00:00
}
2002-01-27 12:45:32 +00:00
} else
continue; //read next line
if (!str_key.size())
continue; //read next line
2001-12-11 20:47:02 +00:00
I18n *i18n = I18n::instance();
2002-01-27 12:45:32 +00:00
if (str_key == "end") {
return ((menu->getCount() == 0) ? True : False);
} else if (str_key == "nop") {
menu->insert(str_label.c_str());
} else if (str_key == "exec") { // exec
if (!(str_label.size() && str_cmd.size())) {
fprintf(stderr,
2001-12-11 20:47:02 +00:00
i18n->getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, ScreenEXECError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [exec] error, "
"no menu label and/or command defined\n"));
cerr<<"Row: "<<row<<endl;
} else
menu->insert(str_label.c_str(), BScreen::EXECUTE, str_cmd.c_str());
} else if (str_key == "exit") { // exit
if (!str_label.size()) {
fprintf(stderr,
i18n->getMessage(
#ifdef NLS
2001-12-11 20:47:02 +00:00
ScreenSet, ScreenEXITError,
2002-01-27 12:45:32 +00:00
#else // !NLS
2001-12-11 20:47:02 +00:00
0, 0,
2002-01-27 12:45:32 +00:00
#endif // NLS
2001-12-11 20:47:02 +00:00
"BScreen::parseMenuFile: [exit] error, "
"no menu label defined\n"));
2002-01-27 12:45:32 +00:00
cerr<<"Row: "<<row<<endl;
} else
menu->insert(str_label.c_str(), BScreen::EXIT);
} // end of exit
else if (str_key == "style") { // style
if (!( str_label.size() && str_cmd.size())) {
fprintf(stderr,
2001-12-11 20:47:02 +00:00
i18n->
getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, ScreenSTYLEError,
#else // !NLS
2001-12-11 20:47:02 +00:00
0, 0,
2002-01-27 12:45:32 +00:00
#endif // NLS
"BScreen::parseMenuFile: [style] error, "
"no menu label and/or filename defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
char *style;
// perform shell style ~ home directory expansion
style = StringUtil::expandFilename(str_cmd.c_str());
menu->insert(str_label.c_str(), BScreen::SETSTYLE, style);
delete style;
}
} // end of style
else if (str_key == "config") {
if (! str_label.size()) {
fprintf(stderr,
2001-12-11 20:47:02 +00:00
i18n->
getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
2001-12-11 20:47:02 +00:00
ScreenSet, ScreenCONFIGError,
2002-01-27 12:45:32 +00:00
#else // !NLS
2001-12-11 20:47:02 +00:00
0, 0,
2002-01-27 12:45:32 +00:00
#endif // NLS
2001-12-11 20:47:02 +00:00
"BScreen::parseMenufile: [config] error, "
"no label defined"));
2002-01-27 12:45:32 +00:00
cerr<<"Row: "<<row<<endl;
} else
menu->insert(str_label.c_str(), configmenu);
} // end of config
else if ( str_key == "include") { // include
if (!str_label.size()) {
fprintf(stderr,
2001-12-11 20:47:02 +00:00
i18n->
getMessage(
2002-01-27 12:45:32 +00:00
#ifdef NLS
ScreenSet, ScreenINCLUDEError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [include] error, "
"no filename defined\n"));
cerr<<"Row: "<<row<<endl;
} else { // start of else 'x'
char *newfile;
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
// perform shell style ~ home directory expansion
newfile = StringUtil::expandFilename(str_label.c_str());
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
if (newfile) {
FILE *submenufile = fopen(newfile, "r");
2001-12-11 20:47:02 +00:00
2002-01-27 12:45:32 +00:00
if (submenufile) {
2001-12-11 20:47:02 +00:00
struct stat buf;
if (fstat(fileno(submenufile), &buf) ||
2002-01-27 12:45:32 +00:00
(! S_ISREG(buf.st_mode))) {
2001-12-11 20:47:02 +00:00
fprintf(stderr,
2002-01-27 12:45:32 +00:00
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenINCLUDEErrorReg,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [include] error: "
"'%s' is not a regular file\n"), newfile);
cerr<<"Row: "<<row<<endl;
2001-12-11 20:47:02 +00:00
}
2002-01-27 12:45:32 +00:00
if (! feof(submenufile)) {
fclose(submenufile);
ifstream subfile(newfile);
if (! parseMenuFile(subfile, menu, row))
fluxbox->saveMenuFilename(newfile);
}
} else
perror(newfile);
delete newfile;
}
} // end of else 'x'
} // end of include
else if (str_key == "submenu") { // sub
if (!str_label.size()) {
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenSUBMENUError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [submenu] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
Rootmenu *submenu = new Rootmenu(this);
if (str_cmd.size())
submenu->setLabel(str_cmd.c_str());
else
submenu->setLabel(str_label.c_str());
parseMenuFile(file, submenu, row);
submenu->update();
menu->insert(str_label.c_str(), submenu);
2002-02-08 13:35:20 +00:00
rootmenuList.push_back(submenu);
2002-01-27 12:45:32 +00:00
}
} // end of sub
else if (str_key == "restart") {
if (!str_label.size()) {
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenRESTARTError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [restart] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else {
if (str_cmd.size())
menu->insert(str_label.c_str(), BScreen::RESTARTOTHER, str_cmd.c_str());
else
menu->insert(str_label.c_str(), BScreen::RESTART);
}
} // end of restart
else if (str_key == "reconfig") { // reconf
if (!str_label.c_str()) {
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenRECONFIGError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [reconfig] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else
menu->insert(str_label.c_str(), BScreen::RECONFIGURE);
} // end of reconf
else if (str_key == "stylesdir" || str_key == "stylesmenu") {
bool newmenu = (str_key == "stylesmenu");
if (!( str_label.size() && str_cmd.size()) && newmenu) {
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenSTYLESDIRError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [stylesdir/stylesmenu]"
" error, no directory defined\n"));
cerr<<"Row: "<<row<<endl;
} else { // else 'y'
2002-02-17 18:56:14 +00:00
createStyleMenu(menu, newmenu, str_label.c_str(), (newmenu) ? str_cmd.c_str() : str_label.c_str());
2002-01-27 12:45:32 +00:00
} // end of else 'y'
} // end of stylesdir
else if (str_key == "workspaces") {
if (!str_label.size()) {
fprintf(stderr,
i18n->getMessage(
#ifdef NLS
ScreenSet, ScreenWORKSPACESError,
#else // !NLS
0, 0,
#endif // NLS
"BScreen:parseMenuFile: [workspaces] error, "
"no menu label defined\n"));
cerr<<"Row: "<<row<<endl;
} else
menu->insert(str_label.c_str(), workspacemenu);
} // end of work
2001-12-11 20:47:02 +00:00
}
}
}
2002-01-27 12:45:32 +00:00
return ((menu->getCount() == 0) ? true : false);
2001-12-11 20:47:02 +00:00
}
2002-02-17 18:56:14 +00:00
void BScreen::createStyleMenu(Rootmenu *menu, bool newmenu, const char *label, const char *directory) {
I18n *i18n = I18n::instance();
// perform shell style ~ home directory expansion
auto_ptr<char> stylesdir(StringUtil::expandFilename(directory));
struct stat statbuf;
if (! stat(stylesdir.get(), &statbuf)) { // stat
if (S_ISDIR(statbuf.st_mode)) { // dir
Rootmenu *stylesmenu;
if (newmenu)
stylesmenu = new Rootmenu(this);
else
stylesmenu = menu;
DIR *d = opendir(stylesdir.get());
int entries = 0;
struct dirent *p;
// get the total number of directory entries
while ((p = readdir(d))) entries++;
rewinddir(d);
char **ls = new char* [entries];
int index = 0;
while ((p = readdir(d)))
ls[index++] = StringUtil::strdup(p->d_name);
qsort(ls, entries, sizeof(char *), dcmp);
int n, slen = strlen(stylesdir.get());
for (n = 0; n < entries; n++) { // for
int nlen = strlen(ls[n]);
char style[MAXPATHLEN + 1];
strncpy(style, stylesdir.get(), slen);
*(style + slen) = '/';
strncpy(style + slen + 1, ls[n], nlen + 1);
if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
stylesmenu->insert(ls[n], BScreen::SETSTYLE, style);
delete [] ls[n];
}
delete [] ls;
stylesmenu->update();
if (newmenu) {
stylesmenu->setLabel(label);
menu->insert(label, stylesmenu);
rootmenuList.push_back(stylesmenu);
}
fluxbox->saveMenuFilename(stylesdir.get());
} else { // dir
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenSTYLESDIRErrorNotDir,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile:"
" [stylesdir/stylesmenu] error, %s is not a"
" directory\n"), stylesdir.get());
} // end of 'dir'
} else { // stat
fprintf(stderr,
i18n->
getMessage(
#ifdef NLS
ScreenSet, ScreenSTYLESDIRErrorNoExist,
#else // !NLS
0, 0,
#endif // NLS
"BScreen::parseMenuFile: [stylesdir/stylesmenu]"
" error, %s does not exist\n"), stylesdir.get());
} // end of 'stat'
}
2001-12-11 20:47:02 +00:00
void BScreen::shutdown(void) {
fluxbox->grab();
XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), NoEventMask);
XSync(getBaseDisplay()->getXDisplay(), False);
2002-02-08 13:35:20 +00:00
{
Workspaces::iterator it = workspacesList.begin();
Workspaces::iterator it_end = workspacesList.end();
for (; it != it_end; ++it) {
(*it)->shutdown();
}
}
2001-12-11 20:47:02 +00:00
2002-02-08 13:35:20 +00:00
{
2002-02-10 22:48:19 +00:00
while (!iconList.empty()) {
iconList.back()->restore();
delete iconList.back(); // the window removes it self from iconlist
2002-02-08 13:35:20 +00:00
}
2001-12-11 20:47:02 +00:00
}
#ifdef SLIT
slit->shutdown();
#endif // SLIT
fluxbox->ungrab();
}
void BScreen::showPosition(int x, int y) {
if (! geom_visible) {
XMoveResizeWindow(getBaseDisplay()->getXDisplay(), geom_window,
2002-01-20 02:17:23 +00:00
(getWidth() - geom_w) / 2,
(getHeight() - geom_h) / 2, geom_w, geom_h);
2001-12-11 20:47:02 +00:00
XMapWindow(getBaseDisplay()->getXDisplay(), geom_window);
XRaiseWindow(getBaseDisplay()->getXDisplay(), geom_window);
geom_visible = True;
}
const int label_size = 1024;
char label[label_size];
snprintf(label, label_size,
I18n::instance()->getMessage(
#ifdef NLS
ScreenSet, ScreenPositionFormat,
#else // !NLS
0, 0,
#endif // NLS
"X: %4d x Y: %4d"), x, y);
XClearWindow(getBaseDisplay()->getXDisplay(), geom_window);
if (I18n::instance()->multibyte())
XmbDrawString(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().font.set, theme->getWindowStyle().l_text_focus_gc,
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(), theme->getBevelWidth() -
theme->getWindowStyle().font.set_extents->max_ink_extent.y,
2001-12-11 20:47:02 +00:00
label, strlen(label));
else
XDrawString(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().l_text_focus_gc,
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(),
theme->getWindowStyle().font.fontstruct->ascent +
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(), label, strlen(label));
}
void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
if (! geom_visible) {
XMoveResizeWindow(getBaseDisplay()->getXDisplay(), geom_window,
(getWidth() - geom_w) / 2,
(getHeight() - geom_h) / 2, geom_w, geom_h);
XMapWindow(getBaseDisplay()->getXDisplay(), geom_window);
XRaiseWindow(getBaseDisplay()->getXDisplay(), geom_window);
geom_visible = True;
}
char label[1024];
sprintf(label,
I18n::instance()->getMessage(
#ifdef NLS
ScreenSet, ScreenGeometryFormat,
#else // !NLS
0, 0,
#endif // NLS
"W: %4d x H: %4d"), gx, gy);
XClearWindow(getBaseDisplay()->getXDisplay(), geom_window);
if (I18n::instance()->multibyte())
XmbDrawString(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().font.set, theme->getWindowStyle().l_text_focus_gc,
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(), theme->getBevelWidth() -
theme->getWindowStyle().font.set_extents->max_ink_extent.y,
2001-12-11 20:47:02 +00:00
label, strlen(label));
else
XDrawString(getBaseDisplay()->getXDisplay(), geom_window,
theme->getWindowStyle().l_text_focus_gc,
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(),
theme->getWindowStyle().font.fontstruct->ascent +
2001-12-11 20:47:02 +00:00
theme->getBevelWidth(), label, strlen(label));
}
void BScreen::hideGeometry(void) {
if (geom_visible) {
XUnmapWindow(getBaseDisplay()->getXDisplay(), geom_window);
geom_visible = False;
}
}
//-------------- nextWorkspace ---------------
// Goes to the workspace "right" of the current
//--------------------------------------------
void BScreen::nextWorkspace(const int delta) {
changeWorkspaceID( (getCurrentWorkspaceID()+delta) % getCount());
2001-12-11 20:47:02 +00:00
}
//------------- prevWorkspace ----------------
// Goes to the workspace "left" of the current
//--------------------------------------------
void BScreen::prevWorkspace(const int delta) {
changeWorkspaceID( (getCurrentWorkspaceID()-delta+getCount()) % getCount());
2001-12-11 20:47:02 +00:00
}
2002-02-02 19:51:15 +00:00
//-------------- rightWorkspace ---------------
// Goes to the workspace "right" of the current
//--------------------------------------------
void BScreen::rightWorkspace(const int delta) {
if (getCurrentWorkspaceID()+delta < getCount())
changeWorkspaceID(getCurrentWorkspaceID()+delta);
2002-02-02 19:51:15 +00:00
}
//------------- leftWorkspace ----------------
// Goes to the workspace "left" of the current
//--------------------------------------------
void BScreen::leftWorkspace(const int delta) {
if (getCurrentWorkspaceID() >= delta)
changeWorkspaceID(getCurrentWorkspaceID()-delta);
2002-02-02 19:51:15 +00:00
}
2002-02-07 14:46:23 +00:00
#ifdef GNOME
void BScreen::initGnomeAtoms(void) {
/* create the GNOME window */
2002-02-17 18:56:14 +00:00
gnome_win = XCreateSimpleWindow(getBaseDisplay()->getXDisplay(),
2002-02-07 14:46:23 +00:00
getRootWindow(), 0, 0, 5, 5, 0, 0, 0);
/* supported WM check */
XChangeProperty(getBaseDisplay()->getXDisplay(),
getRootWindow(), getBaseDisplay()->getGnomeSupportingWMCheckAtom(),
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1);
XChangeProperty(getBaseDisplay()->getXDisplay(), gnome_win,
getBaseDisplay()->getGnomeSupportingWMCheckAtom(),
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1);
2002-02-17 18:56:14 +00:00
2002-02-07 14:46:23 +00:00
Atom gnomeatomlist[] = {
getBaseDisplay()->getGnomeWorkspaceAtom(),
getBaseDisplay()->getGnomeWorkspaceCountAtom(),
getBaseDisplay()->getGnomeStateAtom(),
2002-02-17 18:56:14 +00:00
getBaseDisplay()->getGnomeWorkspaceNamesAtom(),
2002-02-20 22:41:13 +00:00
getBaseDisplay()->getGnomeHintsAtom(),
getBaseDisplay()->getGnomeClientListAtom(),
2002-02-26 22:40:31 +00:00
// getBaseDisplay()->getGnomeLayerAtom(), // not supported yet
2002-02-07 14:46:23 +00:00
};
2002-02-17 18:56:14 +00:00
//list atoms that we support
2002-02-07 14:46:23 +00:00
XChangeProperty(getBaseDisplay()->getXDisplay(), getRootWindow(),
getBaseDisplay()->getGnomeProtAtom(), XA_ATOM, 32, PropModeReplace,
(unsigned char *)gnomeatomlist, (sizeof gnomeatomlist)/sizeof gnomeatomlist[0]);
}
2002-02-20 22:41:13 +00:00
void BScreen::updateGnomeClientList() {
2002-02-21 12:03:40 +00:00
int num=0;
Workspaces::iterator workspace_it = workspacesList.begin();
Workspaces::iterator workspace_it_end = workspacesList.end();
for (; workspace_it != workspace_it_end; ++workspace_it) {
num += (*workspace_it)->getWindowList().size();
}
//int num = getCurrentWorkspace()->getWindowList().size();
2002-02-20 22:41:13 +00:00
Window *wl = new Window[num];
2002-02-21 12:03:40 +00:00
workspace_it = workspacesList.begin();
2002-02-20 22:41:13 +00:00
int win=0;
2002-02-21 12:03:40 +00:00
for (; workspace_it != workspace_it_end; ++workspace_it) {
// Fill in array of window ID's
Workspace::Windows::iterator it = (*workspace_it)->getWindowList().begin();
Workspace::Windows::iterator it_end = (*workspace_it)->getWindowList().end();
for (; it != it_end; ++it) {
//check if the window don't want to be visible in the list
if (! ( (*it)->getGnomeHints() & FluxboxWindow::WIN_STATE_HIDDEN) ) {
wl[win++] = (*it)->getClientWindow();
}
2002-02-20 22:41:13 +00:00
}
}
2002-02-21 12:03:40 +00:00
//number of windows to show in client list
2002-02-20 22:41:13 +00:00
num = win;
XChangeProperty(getBaseDisplay()->getXDisplay(),
getRootWindow(), getBaseDisplay()->getGnomeClientListAtom(), XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)wl, num);
if (wl)
delete wl;
}
2002-02-07 14:46:23 +00:00
#endif //!GNOME