fluxbox/src/Window.cc

3391 lines
106 KiB
C++
Raw Normal View History

// Window.cc for Fluxbox Window Manager
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
//
2001-12-11 20:47:02 +00:00
// Window.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
2001-12-11 20:47:02 +00:00
//
// 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
2001-12-11 20:47:02 +00:00
// 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.
2003-05-24 13:02:49 +00:00
// $Id: Window.cc,v 1.186 2003/05/24 13:02:49 fluxgen Exp $
2002-04-04 22:39:52 +00:00
#include "Window.hh"
2003-04-14 15:01:55 +00:00
#include "WinClient.hh"
2001-12-11 20:47:02 +00:00
#include "i18n.hh"
#include "fluxbox.hh"
#include "Screen.hh"
2002-01-06 11:07:42 +00:00
#include "StringUtil.hh"
2002-11-17 11:29:06 +00:00
#include "Netizen.hh"
#include "FbWinFrameTheme.hh"
#include "MenuTheme.hh"
2003-04-14 15:01:55 +00:00
#include "TextButton.hh"
#include "EventManager.hh"
2003-04-15 12:22:52 +00:00
#include "FbAtoms.hh"
2003-04-25 11:11:27 +00:00
#include "RootTheme.hh"
#include "Workspace.hh"
2003-05-15 11:17:29 +00:00
#include "LayerMenu.hh"
#include "FbWinFrame.hh"
2003-04-14 15:01:55 +00:00
2002-10-13 21:54:36 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
2003-05-15 11:17:29 +00:00
#ifdef SHAPE
#include <X11/extensions/shape.h>
#endif // SHAPE
2002-10-13 21:54:36 +00:00
2002-08-11 22:44:29 +00:00
//use GNU extensions
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
2001-12-11 20:47:02 +00:00
2002-08-11 22:44:29 +00:00
#include <X11/Xatom.h>
#include <X11/keysym.h>
2001-12-11 20:47:02 +00:00
2002-08-11 22:44:29 +00:00
#include <cstring>
#include <cstdio>
2002-01-05 10:58:48 +00:00
#include <iostream>
2003-04-27 02:26:21 +00:00
#include <cassert>
2003-04-14 15:01:55 +00:00
2001-12-11 20:47:02 +00:00
using namespace std;
namespace {
void grabButton(Display *display, unsigned int button,
2003-02-19 14:53:38 +00:00
Window window, Cursor cursor) {
//numlock
XGrabButton(display, button, Mod1Mask|Mod2Mask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//scrolllock
XGrabButton(display, button, Mod1Mask|Mod5Mask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//capslock
XGrabButton(display, button, Mod1Mask|LockMask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//capslock+numlock
XGrabButton(display, Button1, Mod1Mask|LockMask|Mod2Mask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//capslock+scrolllock
XGrabButton(display, button, Mod1Mask|LockMask|Mod5Mask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//capslock+numlock+scrolllock
2003-04-14 15:01:55 +00:00
XGrabButton(display, button, Mod1Mask|LockMask|Mod2Mask|Mod5Mask, window,
True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
//numlock+scrollLock
XGrabButton(display, button, Mod1Mask|Mod2Mask|Mod5Mask, window, True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, cursor);
}
// X event scanner for enter/leave notifies - adapted from twm
typedef struct scanargs {
Window w;
Bool leave, inferior, enter;
} scanargs;
// look for valid enter or leave events (that may invalidate the earlier one we are interested in)
static Bool queueScanner(Display *, XEvent *e, char *args) {
if (e->type == LeaveNotify &&
e->xcrossing.window == ((scanargs *) args)->w &&
e->xcrossing.mode == NotifyNormal) {
((scanargs *) args)->leave = true;
((scanargs *) args)->inferior = (e->xcrossing.detail == NotifyInferior);
} else if (e->type == EnterNotify &&
e->xcrossing.mode == NotifyUngrab)
((scanargs *) args)->enter = true;
return false;
}
/// returns the deepest transientFor, asserting against a close loop
WinClient *getRootTransientFor(WinClient *client) {
while (client->transientFor()) {
assert(client != client->transientFor());
client = client->transientFor();
}
return client;
}
/// raise window and do the same for each transient of the current window
2003-02-19 14:53:38 +00:00
void raiseFluxboxWindow(FluxboxWindow &win) {
if (win.oplock) return;
win.oplock = true;
2003-02-19 14:53:38 +00:00
if (!win.isIconic()) {
2003-05-15 11:17:29 +00:00
win.screen().updateNetizenWindowRaise(win.clientWindow());
win.layerItem().raise();
2003-02-19 14:53:38 +00:00
}
// for each transient do raise
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
2003-02-19 14:53:38 +00:00
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
raiseFluxboxWindow(*(*it)->fbwindow());
2003-02-19 14:53:38 +00:00
}
win.oplock = false;
2003-02-19 14:53:38 +00:00
}
/// lower window and do the same for each transient it holds
void lowerFluxboxWindow(FluxboxWindow &win) {
if (win.oplock) return;
win.oplock = true;
2003-02-19 14:53:38 +00:00
if (!win.isIconic()) {
2003-05-15 11:17:29 +00:00
win.screen().updateNetizenWindowLower(win.clientWindow());
win.layerItem().lower();
2003-02-19 14:53:38 +00:00
}
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
2003-02-19 14:53:38 +00:00
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
lowerFluxboxWindow(*(*it)->fbwindow());
2003-02-19 14:53:38 +00:00
}
win.oplock = false;
2003-02-19 14:53:38 +00:00
}
/// raise window and do the same for each transient it holds
void tempRaiseFluxboxWindow(FluxboxWindow &win) {
if (win.oplock) return;
win.oplock = true;
if (!win.isIconic()) {
// don't update netizen, as it is only temporary
2003-05-15 11:17:29 +00:00
win.layerItem().tempRaise();
}
// for each transient do raise
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
tempRaiseFluxboxWindow(*(*it)->fbwindow());
}
win.oplock = false;
}
2003-04-14 15:01:55 +00:00
class SetClientCmd:public FbTk::Command {
public:
explicit SetClientCmd(WinClient &client):m_client(client) {
}
void execute() {
if (m_client.m_win != 0)
m_client.m_win->setCurrentClient(m_client);
}
private:
WinClient &m_client;
};
};
template <>
void LayerMenuItem<FluxboxWindow>::click(int button, int time) {
m_object->moveToLayer(m_layernum);
}
2003-05-10 14:27:57 +00:00
//int FluxboxWindow::PropBlackboxHintsElements = 5;
//int FluxboxWindow::PropBlackboxAttributesElements = 8;
2003-04-14 15:01:55 +00:00
FluxboxWindow::FluxboxWindow(WinClient &client, BScreen &scr, FbWinFrameTheme &tm,
2003-02-03 13:56:12 +00:00
FbTk::MenuTheme &menutheme,
FbTk::XLayer &layer):
oplock(false),
2002-12-01 13:42:15 +00:00
m_hintsig(*this),
m_statesig(*this),
m_layersig(*this),
2002-12-01 13:42:15 +00:00
m_workspacesig(*this),
m_diesig(*this),
2002-12-01 13:42:15 +00:00
moving(false), resizing(false), shaded(false), maximized(false),
iconic(false), focused(false),
stuck(false), send_focus_message(false), m_managed(false),
2003-05-10 16:53:09 +00:00
m_screen(scr),
m_timer(this),
2002-12-01 13:42:15 +00:00
display(0),
2003-05-15 11:17:29 +00:00
m_layermenu(new LayerMenu<FluxboxWindow>(menutheme,
2003-05-15 12:00:46 +00:00
scr.screenNumber(),
2003-05-15 23:30:07 +00:00
scr.imageControl(),
2003-05-15 11:17:29 +00:00
*scr.layerManager().getLayer(Fluxbox::instance()->getMenuLayer()),
this,
false)),
2003-05-24 13:02:49 +00:00
m_windowmenu(menutheme, scr.screenNumber(), scr.imageControl()),
2003-05-10 16:53:09 +00:00
m_old_decoration(DECOR_NORMAL),
2003-04-14 15:01:55 +00:00
m_client(&client),
2003-05-15 23:30:07 +00:00
m_frame(new FbWinFrame(tm, scr.imageControl(), scr.screenNumber(), 0, 0, 100, 100)),
2003-05-15 11:17:29 +00:00
m_layeritem(m_frame->window(), layer),
m_layernum(layer.getLayerNum()),
m_parent(scr.rootWindow()) {
2003-04-14 15:01:55 +00:00
init();
}
FluxboxWindow::FluxboxWindow(Window w, BScreen &scr, FbWinFrameTheme &tm,
FbTk::MenuTheme &menutheme,
FbTk::XLayer &layer):
oplock(false),
2003-04-14 15:01:55 +00:00
m_hintsig(*this),
m_statesig(*this),
m_layersig(*this),
m_workspacesig(*this),
m_diesig(*this),
moving(false), resizing(false), shaded(false), maximized(false),
iconic(false), focused(false),
stuck(false), send_focus_message(false), m_managed(false),
2003-05-10 16:53:09 +00:00
m_screen(scr),
m_timer(this),
2003-04-14 15:01:55 +00:00
display(0),
2003-05-15 11:17:29 +00:00
m_layermenu(new LayerMenu<FluxboxWindow>(menutheme,
2003-05-15 12:00:46 +00:00
scr.screenNumber(),
2003-05-15 23:30:07 +00:00
scr.imageControl(),
2003-05-15 11:17:29 +00:00
*scr.layerManager().getLayer(Fluxbox::instance()->getMenuLayer()),
this,
false)),
2003-05-24 13:02:49 +00:00
m_windowmenu(menutheme, scr.screenNumber(), scr.imageControl()),
2003-05-10 16:53:09 +00:00
m_old_decoration(DECOR_NORMAL),
2003-04-14 15:01:55 +00:00
m_client(new WinClient(w, *this)),
2003-05-15 23:30:07 +00:00
m_frame(new FbWinFrame(tm, scr.imageControl(), scr.screenNumber(), 0, 0, 100, 100)),
2003-05-15 11:17:29 +00:00
m_layeritem(m_frame->window(), layer),
m_layernum(layer.getLayerNum()),
m_parent(scr.rootWindow()) {
2003-04-14 15:01:55 +00:00
assert(w != 0);
init();
}
FluxboxWindow::~FluxboxWindow() {
#ifdef DEBUG
cerr<<__FILE__<<"("<<__LINE__<<"): starting ~FluxboxWindow("<<this<<")"<<endl;
#endif // DEBUG
2003-04-15 14:40:24 +00:00
if (moving || resizing || m_attaching_tab) {
2003-05-10 16:53:09 +00:00
screen().hideGeometry();
2003-04-14 15:01:55 +00:00
XUngrabPointer(display, CurrentTime);
}
Client2ButtonMap::iterator it = m_labelbuttons.begin();
Client2ButtonMap::iterator it_end = m_labelbuttons.end();
for (; it != it_end; ++it) {
2003-05-15 11:17:29 +00:00
frame().removeLabelButton(*(*it).second);
2003-04-14 15:01:55 +00:00
delete (*it).second;
}
m_labelbuttons.clear();
2003-05-10 16:53:09 +00:00
m_timer.stop();
2003-04-14 15:01:55 +00:00
// notify die
m_diesig.notify();
if (m_client != 0)
delete m_client; // this also removes client from our list
m_client = 0;
if (m_clientlist.size() > 1) {
cerr<<__FILE__<<"("<<__FUNCTION__<<") WARNING! clientlist > 1"<<endl;
while (!m_clientlist.empty()) {
detachClient(*m_clientlist.back());
}
}
2003-05-15 11:17:29 +00:00
Fluxbox::instance()->removeWindowSearch(frame().window().window());
2003-04-14 15:01:55 +00:00
#ifdef DEBUG
cerr<<__FILE__<<"("<<__LINE__<<"): ~FluxboxWindow("<<this<<")"<<endl;
#endif // DEBUG
}
2003-02-03 13:56:12 +00:00
2003-04-15 14:40:24 +00:00
void FluxboxWindow::init() {
// so parent menu don't kill us
m_layermenu->setInternalMenu();
2003-04-15 14:40:24 +00:00
m_attaching_tab = 0;
2003-04-14 15:01:55 +00:00
assert(m_client);
2003-05-14 14:43:06 +00:00
// check for shape extension and whether the window is shaped
m_shaped = false;
#ifdef SHAPE
if (Fluxbox::instance()->haveShape()) {
Display *disp = FbTk::App::instance()->display();
int not_used;
unsigned int not_used2;
int shaped;
XShapeSelectInput(disp, m_client->window(), ShapeNotifyMask);
XShapeQueryExtents(disp, m_client->window(),
&shaped, /// bShaped
&not_used, &not_used, // xbs, ybs
&not_used2, &not_used2, // wbs, hbs
&not_used, // cShaped
&not_used, &not_used, // xcs, ycs
&not_used2, &not_used2); // wcs, hcs
m_shaped = (shaped != 0 ? true : false);
}
#endif // SHAPE
2003-04-14 15:01:55 +00:00
//!! TODO init of client should be better
// we don't want to duplicate code here and in attachClient
m_clientlist.push_back(m_client);
#ifdef DEBUG
2003-04-15 14:40:24 +00:00
cerr<<__FILE__<<": FluxboxWindow::init(this="<<this<<", client="<<hex<<
2003-05-15 11:17:29 +00:00
m_client->window()<<", frame = "<<frame().window().window()<<dec<<")"<<endl;
2003-04-15 14:40:24 +00:00
#endif // DEBUG
2003-04-16 22:17:46 +00:00
2003-05-17 11:08:06 +00:00
Fluxbox &fluxbox = *Fluxbox::instance();
2003-05-14 14:43:06 +00:00
2003-05-17 11:08:06 +00:00
// setup cursors for resize grips
frame().gripLeft().setCursor(fluxbox.getLowerLeftAngleCursor());
frame().gripRight().setCursor(fluxbox.getLowerRightAngleCursor());
2003-05-14 14:43:06 +00:00
2003-05-15 11:17:29 +00:00
frame().resize(m_client->width(), m_client->height());
TextButton *btn = new TextButton(frame().label(),
frame().theme().font(),
2003-04-14 15:01:55 +00:00
m_client->title());
2003-05-15 11:17:29 +00:00
btn->setJustify(frame().theme().justify());
2003-04-14 15:01:55 +00:00
m_labelbuttons[m_client] = btn;
2003-05-15 11:17:29 +00:00
frame().addLabelButton(*btn);
frame().setLabelButtonFocus(*btn);
2003-04-16 12:27:49 +00:00
btn->show();
2003-04-14 15:01:55 +00:00
FbTk::EventManager &evm = *FbTk::EventManager::instance();
// we need motion notify so we mask it
btn->window().setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask |
2003-05-08 15:06:59 +00:00
ButtonMotionMask | EnterWindowMask);
2003-04-14 15:01:55 +00:00
FbTk::RefCount<FbTk::Command> set_client_cmd(new SetClientCmd(*m_client));
btn->setOnClick(set_client_cmd);
evm.add(*this, btn->window()); // we take care of button events for this
2003-04-28 12:56:38 +00:00
evm.add(*this, m_client->window());
2003-04-14 15:01:55 +00:00
2003-05-15 11:17:29 +00:00
// frame().reconfigure();
2003-02-03 13:56:12 +00:00
// redirect events from frame to us
2003-05-15 11:17:29 +00:00
frame().setEventHandler(*this);
2003-05-10 16:53:09 +00:00
m_last_focus_time.tv_sec = m_last_focus_time.tv_usec = 0;
// display connection
display = FbTk::App::instance()->display();
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.workspace = m_workspace_number = m_window_number = -1;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags = m_blackbox_attrib.attrib = m_blackbox_attrib.stack = 0;
m_blackbox_attrib.premax_x = m_blackbox_attrib.premax_y = 0;
m_blackbox_attrib.premax_w = m_blackbox_attrib.premax_h = 0;
2002-12-01 13:42:15 +00:00
//use tab as default
decorations.tab = true;
// enable decorations
2002-12-01 13:42:15 +00:00
decorations.enabled = true;
// set default values for decoration
2002-12-01 13:42:15 +00:00
decorations.menu = true; //override menu option
// all decorations on by default
2002-12-01 13:42:15 +00:00
decorations.titlebar = decorations.border = decorations.handle = true;
2003-02-19 14:53:38 +00:00
decorations.maximize = decorations.close =
decorations.sticky = decorations.shade = decorations.tab = true;
2002-12-01 13:42:15 +00:00
functions.resize = functions.move = functions.iconify = functions.maximize = true;
functions.close = decorations.close = false;
getBlackboxHints();
2003-04-14 15:01:55 +00:00
if (! m_client->blackbox_hint)
getMWMHints();
// get size, aspect, minimum/maximum size and other hints set
// by the client
getWMProtocols();
getWMHints();
getWMNormalHints();
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
//!!
2002-12-01 13:42:15 +00:00
// fetch client size and placement
XWindowAttributes wattrib;
2003-04-14 15:01:55 +00:00
if (! m_client->getAttrib(wattrib) ||
!wattrib.screen // no screen? ??
2003-05-14 14:43:06 +00:00
|| wattrib.override_redirect) { // override redirect
2002-12-01 13:42:15 +00:00
return;
}
// save old border width so we can restore it later
2003-04-14 15:01:55 +00:00
m_client->old_bw = wattrib.border_width;
m_client->x = wattrib.x; m_client->y = wattrib.y;
2002-12-01 13:42:15 +00:00
2003-05-17 11:08:06 +00:00
fluxbox.saveWindowSearch(frame().window().window(), this);
2003-02-09 14:11:14 +00:00
2003-05-17 11:08:06 +00:00
m_timer.setTimeout(fluxbox.getAutoRaiseDelay());
2003-05-10 16:53:09 +00:00
m_timer.fireOnce(true);
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
if (m_client->initial_state == WithdrawnState) {
2002-12-01 13:42:15 +00:00
return;
}
2001-12-11 20:47:02 +00:00
m_managed = true; //this window is managed
// update transient infomation
m_client->updateTransientInfo();
2002-12-01 13:42:15 +00:00
// adjust the window decorations based on transience and window sizes
if (m_client->isTransient()) {
2002-12-01 13:42:15 +00:00
decorations.maximize = functions.maximize = false;
decorations.handle = decorations.border = false;
}
2003-04-14 15:01:55 +00:00
if ((m_client->normal_hint_flags & PMinSize) &&
(m_client->normal_hint_flags & PMaxSize) &&
m_client->max_width != 0 && m_client->max_width <= m_client->min_width &&
m_client->max_height != 0 && m_client->max_height <= m_client->min_height) {
2002-12-01 13:42:15 +00:00
decorations.maximize = decorations.handle =
functions.resize = functions.maximize = false;
decorations.tab = false; //no tab for this window
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
upsize();
2002-12-01 13:42:15 +00:00
bool place_window = true;
2003-05-17 11:08:06 +00:00
if (fluxbox.isStartup() || m_client->isTransient() ||
2003-04-14 15:01:55 +00:00
m_client->normal_hint_flags & (PPosition|USPosition)) {
2002-12-01 13:42:15 +00:00
setGravityOffsets();
2001-12-11 20:47:02 +00:00
2003-05-17 11:08:06 +00:00
if (! fluxbox.isStartup()) {
2001-12-17 00:46:15 +00:00
2003-05-15 11:17:29 +00:00
int real_x = frame().x();
int real_y = frame().y();
2001-12-17 00:46:15 +00:00
2002-12-01 13:42:15 +00:00
if (real_x >= 0 &&
2003-05-15 11:17:29 +00:00
real_y + frame().y() >= 0 &&
2003-05-15 12:00:46 +00:00
real_x <= (signed) screen().width() &&
real_y <= (signed) screen().height())
2002-12-01 13:42:15 +00:00
place_window = false;
2002-03-19 14:30:43 +00:00
2002-12-01 13:42:15 +00:00
} else
place_window = false;
2001-12-17 00:46:15 +00:00
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
associateClientWindow();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
grabButtons();
2002-12-01 13:42:15 +00:00
positionWindows();
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
if (m_workspace_number < 0 || m_workspace_number >= screen().getCount())
2003-05-15 12:00:46 +00:00
m_workspace_number = screen().currentWorkspaceID();
2003-02-16 17:57:54 +00:00
restoreAttributes();
2003-05-15 11:17:29 +00:00
frame().move(wattrib.x, wattrib.y);
frame().resizeForClient(wattrib.width, wattrib.height);
2003-02-19 14:53:38 +00:00
// if we're a transient then we should be on the same layer as our parent
if (m_client->isTransient() &&
m_client->transientFor()->fbwindow() &&
m_client->transientFor()->fbwindow() != this)
2003-05-15 11:17:29 +00:00
layerItem().setLayer(m_client->transientFor()->fbwindow()->layerItem().getLayer());
2003-04-14 15:01:55 +00:00
else // if no parent then set default layer
2003-02-19 14:53:38 +00:00
moveToLayer(m_layernum);
if (!place_window)
2003-05-15 11:17:29 +00:00
moveResize(frame().x(), frame().y(), frame().width(), frame().height());
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
screen().getWorkspace(m_workspace_number)->addWindow(*this, place_window);
2001-12-11 20:47:02 +00:00
if (shaded) { // start shaded
2002-12-01 13:42:15 +00:00
shaded = false;
shade();
}
2001-12-11 20:47:02 +00:00
if (maximized && functions.maximize) { // start maximized
2002-12-01 13:42:15 +00:00
maximized = false;
maximize();
2002-12-01 13:42:15 +00:00
}
2002-12-01 13:42:15 +00:00
if (stuck) {
stuck = false;
stick();
deiconify(); //we're omnipresent and visible
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
setState(m_current_state);
2003-05-15 11:17:29 +00:00
frame().reconfigure();
2003-04-16 22:17:46 +00:00
sendConfigureNotify();
// no focus default
2002-12-01 13:42:15 +00:00
setFocusFlag(false);
2002-02-07 14:41:52 +00:00
2003-05-14 14:43:06 +00:00
if (m_shaped)
shape();
}
/// apply shape to this window
void FluxboxWindow::shape() {
#ifdef SHAPE
if (m_shaped) {
Display *disp = FbTk::App::instance()->display();
XShapeCombineShape(disp,
2003-05-15 11:17:29 +00:00
frame().window().window(), ShapeBounding,
0, frame().clientArea().y(), // xOff, yOff
2003-05-14 14:43:06 +00:00
m_client->window(),
ShapeBounding, ShapeSet);
XFlush(disp);
}
#endif // SHAPE
2001-12-11 20:47:02 +00:00
}
2003-05-14 14:43:06 +00:00
2003-04-14 15:01:55 +00:00
/// attach a client to this window and destroy old window
void FluxboxWindow::attachClient(WinClient &client) {
//!! TODO: check for isGroupable in client
if (client.m_win == this)
return;
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
// reparent client win to this frame
2003-05-15 11:17:29 +00:00
frame().setClientWindow(client);
2003-04-28 12:56:38 +00:00
FbTk::EventManager &evm = *FbTk::EventManager::instance();
2003-04-14 15:01:55 +00:00
if (client.fbwindow() != 0) {
FluxboxWindow *old_win = client.fbwindow(); // store old window
2003-04-14 15:01:55 +00:00
Fluxbox *fb = Fluxbox::instance();
// make sure we set new window search for each client
ClientList::iterator client_it = old_win->clientList().begin();
ClientList::iterator client_it_end = old_win->clientList().end();
for (; client_it != client_it_end; ++client_it) {
fb->saveWindowSearch((*client_it)->window(), this);
2003-04-28 12:56:38 +00:00
evm.add(*this, (*client_it)->window());
2003-04-14 15:01:55 +00:00
// reparent window to this
2003-05-15 11:17:29 +00:00
frame().setClientWindow(**client_it);
resizeClient(**client_it,
2003-05-15 11:17:29 +00:00
frame().clientArea().width(),
frame().clientArea().height());
2003-04-14 15:01:55 +00:00
(*client_it)->m_win = this;
2003-04-15 12:22:52 +00:00
// create a labelbutton for this client and
// associate it with the pointer
2003-05-15 11:17:29 +00:00
TextButton *btn = new TextButton(frame().label(),
frame().theme().font(),
2003-04-14 15:01:55 +00:00
(*client_it)->title());
2003-05-15 11:17:29 +00:00
btn->setJustify(frame().theme().justify());
2003-04-14 15:01:55 +00:00
m_labelbuttons[(*client_it)] = btn;
2003-05-15 11:17:29 +00:00
frame().addLabelButton(*btn);
2003-04-14 15:01:55 +00:00
btn->show();
// we need motion notify so we mask it
2003-04-15 12:22:52 +00:00
btn->window().setEventMask(ExposureMask | ButtonPressMask |
2003-05-08 15:14:50 +00:00
ButtonReleaseMask | ButtonMotionMask |
EnterWindowMask);
2003-04-14 15:01:55 +00:00
2003-04-15 12:22:52 +00:00
FbTk::RefCount<FbTk::Command>
set_client_cmd(new SetClientCmd(*(*client_it)));
2003-04-14 15:01:55 +00:00
btn->setOnClick(set_client_cmd);
evm.add(*this, btn->window()); // we take care of button events for this
}
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
// add client and move over all attached clients
// from the old window to this list
m_clientlist.splice(m_clientlist.end(), old_win->m_clientlist);
old_win->m_client = 0;
delete old_win;
2003-05-15 11:17:29 +00:00
} else { // client.fbwindow() == 0
2003-04-14 15:01:55 +00:00
// create a labelbutton for this client and associate it with the pointer
2003-05-15 11:17:29 +00:00
TextButton *btn = new TextButton(frame().label(),
frame().theme().font(),
2003-04-14 15:01:55 +00:00
client.title());
m_labelbuttons[&client] = btn;
2003-05-15 11:17:29 +00:00
frame().addLabelButton(*btn);
2003-04-14 15:01:55 +00:00
btn->show();
FbTk::EventManager &evm = *FbTk::EventManager::instance();
// we need motion notify so we mask it
2003-04-15 12:22:52 +00:00
btn->window().setEventMask(ExposureMask | ButtonPressMask |
2003-05-08 15:14:50 +00:00
ButtonReleaseMask | ButtonMotionMask |
EnterWindowMask);
2003-04-14 15:01:55 +00:00
FbTk::RefCount<FbTk::Command> set_client_cmd(new SetClientCmd(client));
btn->setOnClick(set_client_cmd);
evm.add(*this, btn->window()); // we take care of button events for this
client.m_win = this;
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
Fluxbox::instance()->saveWindowSearch(client.window(), this);
2002-12-01 13:42:15 +00:00
}
2003-05-15 11:17:29 +00:00
frame().reconfigure();
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
// keep the current window on top
m_client->raise();
2002-12-01 13:42:15 +00:00
2003-04-15 12:22:52 +00:00
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
}
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
/// detach client from window and create a new window for it
bool FluxboxWindow::detachClient(WinClient &client) {
if (client.m_win != this || numClients() <= 1)
return false;
removeClient(client);
2003-05-10 16:53:09 +00:00
client.m_win = screen().createWindow(client);
2003-04-14 15:01:55 +00:00
m_client->raise();
setInputFocus();
return true;
}
2003-04-16 12:27:49 +00:00
void FluxboxWindow::detachCurrentClient() {
// should only operate if we had more than one client
if (numClients() <= 1)
return;
detachClient(*m_client);
}
2003-04-14 15:01:55 +00:00
/// removes client from client list, does not create new fluxboxwindow for it
bool FluxboxWindow::removeClient(WinClient &client) {
if (client.m_win != this || numClients() == 0)
return false;
#ifdef DEBUG
2003-04-14 15:01:55 +00:00
cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"]"<<endl;
#endif // DEBUG
2003-04-14 15:01:55 +00:00
// if it is our active client, deal with it...
if (m_client == &client) {
2003-04-14 15:01:55 +00:00
// set next client to be focused
// if the client we're about to remove is the last client then set prev client
if (&client == m_clientlist.back())
prevClient();
else
nextClient();
}
2003-04-14 15:01:55 +00:00
client.m_win = 0;
m_clientlist.remove(&client);
if (m_client == &client) {
if (m_clientlist.empty())
m_client = 0;
else
// this really shouldn't happen
m_client = m_clientlist.back();
}
2003-04-14 15:01:55 +00:00
2003-04-28 12:56:38 +00:00
FbTk::EventManager &evm = *FbTk::EventManager::instance();
evm.remove(client.window());
2003-04-14 15:01:55 +00:00
FbTk::Button *label_btn = m_labelbuttons[&client];
if (label_btn != 0) {
2003-05-15 11:17:29 +00:00
frame().removeLabelButton(*label_btn);
2003-04-28 12:56:38 +00:00
evm.remove(label_btn->window());
2003-04-14 15:01:55 +00:00
delete label_btn;
label_btn = 0;
}
m_labelbuttons.erase(&client);
#ifdef DEBUG
cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"] numClients = "<<numClients()<<endl;
#endif // DEBUG
return true;
}
/// returns WinClient of window we're searching for
WinClient *FluxboxWindow::findClient(Window win) {
std::list<WinClient *>::iterator it = m_clientlist.begin();
std::list<WinClient *>::iterator it_end = m_clientlist.end();
for (; it != it_end; ++it) {
if ((*it)->window() == win)
return (*it);
}
// failure
return 0;
}
/// raise and focus next client
void FluxboxWindow::nextClient() {
2003-04-15 12:22:52 +00:00
if (numClients() <= 1)
2003-04-14 15:01:55 +00:00
return;
ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), m_client);
2003-04-15 12:22:52 +00:00
if (it == m_clientlist.end()) {
m_client = m_clientlist.front();
return;
}
2003-04-14 15:01:55 +00:00
it++;
if (it == m_clientlist.end())
m_client = m_clientlist.front();
else
m_client = *it;
m_client->raise();
2003-05-15 11:17:29 +00:00
frame().setLabelButtonFocus(*m_labelbuttons[m_client]);
2003-04-14 15:01:55 +00:00
setInputFocus();
}
void FluxboxWindow::prevClient() {
2003-04-15 12:22:52 +00:00
if (numClients() <= 1)
2003-04-14 15:01:55 +00:00
return;
ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), m_client);
2003-04-15 12:22:52 +00:00
if (it == m_clientlist.end()) {
m_client = m_clientlist.front();
return;
}
2003-04-14 15:01:55 +00:00
if (it == m_clientlist.begin())
m_client = m_clientlist.back();
else
m_client = *(--it);
m_client->raise();
2003-05-15 11:17:29 +00:00
frame().setLabelButtonFocus(*m_labelbuttons[m_client]);
2003-04-14 15:01:55 +00:00
setInputFocus();
}
bool FluxboxWindow::setCurrentClient(WinClient &client, bool setinput) {
2003-04-14 15:01:55 +00:00
// make sure it's in our list
if (client.m_win != this)
return false;
2003-04-14 15:01:55 +00:00
m_client = &client;
m_client->raise();
2003-05-15 11:17:29 +00:00
frame().setLabelButtonFocus(*m_labelbuttons[m_client]);
return setinput && setInputFocus();
2001-12-11 20:47:02 +00:00
}
2002-10-22 14:39:21 +00:00
bool FluxboxWindow::isGroupable() const {
if (isResizable() && isMaximizable() && !winClient().isTransient())
2002-12-01 13:42:15 +00:00
return true;
return false;
2002-10-22 14:39:21 +00:00
}
void FluxboxWindow::associateClientWindow() {
2003-04-14 15:01:55 +00:00
m_client->setBorderWidth(0);
updateTitleFromClient();
updateIconNameFromClient();
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
frame().setClientWindow(*m_client);
frame().resizeForClient(m_client->width(), m_client->height());
// make sure the frame reconfigures
2003-05-15 11:17:29 +00:00
frame().reconfigure();
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::grabButtons() {
2002-12-01 13:42:15 +00:00
Fluxbox *fluxbox = Fluxbox::instance();
2002-12-01 13:42:15 +00:00
XGrabButton(display, Button1, AnyModifier,
2003-05-15 11:17:29 +00:00
frame().clientArea().window(), True, ButtonPressMask,
GrabModeSync, GrabModeSync, None, None);
2003-05-15 11:17:29 +00:00
XUngrabButton(display, Button1, Mod1Mask|Mod2Mask|Mod3Mask, frame().clientArea().window());
2003-05-15 11:17:29 +00:00
XGrabButton(display, Button1, Mod1Mask, frame().window().window(), True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, fluxbox->getMoveCursor());
2002-12-01 13:42:15 +00:00
//----grab with "all" modifiers
2003-05-15 11:17:29 +00:00
grabButton(display, Button1, frame().window().window(), fluxbox->getMoveCursor());
2003-05-15 11:17:29 +00:00
XGrabButton(display, Button2, Mod1Mask, frame().window().window(), True,
ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
2003-05-15 11:17:29 +00:00
XGrabButton(display, Button3, Mod1Mask, frame().window().window(), True,
ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
GrabModeAsync, None, fluxbox->getLowerRightAngleCursor());
2002-12-01 13:42:15 +00:00
//---grab with "all" modifiers
2003-05-15 11:17:29 +00:00
grabButton(display, Button3, frame().window().window(), fluxbox->getLowerRightAngleCursor());
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::reconfigure() {
upsize();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
positionWindows();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
setFocusFlag(focused);
2001-12-11 20:47:02 +00:00
2003-05-15 11:17:29 +00:00
moveResize(frame().x(), frame().y(), frame().width(), frame().height());
2002-10-13 21:54:36 +00:00
2002-12-01 13:42:15 +00:00
grabButtons();
2001-12-11 20:47:02 +00:00
2003-05-15 11:17:29 +00:00
frame().setDoubleClickTime(Fluxbox::instance()->getDoubleClickInterval());
m_windowmenu.reconfigure();
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::positionWindows() {
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
frame().window().setBorderWidth(screen().rootTheme().borderWidth());
frame().clientArea().setBorderWidth(0); // client area bordered by other things
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
frame().titlebar().setBorderWidth(screen().rootTheme().borderWidth());
if (decorations.titlebar) {
2003-05-15 11:17:29 +00:00
frame().showTitlebar();
} else {
2003-05-15 11:17:29 +00:00
frame().hideTitlebar();
}
2003-05-15 11:17:29 +00:00
frame().handle().setBorderWidth(screen().rootTheme().borderWidth());
frame().gripLeft().setBorderWidth(screen().rootTheme().borderWidth());
frame().gripRight().setBorderWidth(screen().rootTheme().borderWidth());
2002-12-01 13:42:15 +00:00
if (decorations.handle)
2003-05-15 11:17:29 +00:00
frame().showHandle();
else
2003-05-15 11:17:29 +00:00
frame().hideHandle();
2003-05-15 11:17:29 +00:00
frame().reconfigure();
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
}
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
/// update current client title and title in our frame
void FluxboxWindow::updateTitleFromClient() {
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
m_client->updateTitle();
m_labelbuttons[m_client]->setText(m_client->title());
m_labelbuttons[m_client]->clear(); // redraw text
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
/// update icon title from client
void FluxboxWindow::updateIconNameFromClient() {
2003-04-14 15:01:55 +00:00
m_client->updateIconTitle();
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::getWMProtocols() {
Atom *proto = 0;
2002-12-01 13:42:15 +00:00
int num_return = 0;
2003-04-14 15:01:55 +00:00
FbAtoms *fbatoms = FbAtoms::instance();
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
if (XGetWMProtocols(display, m_client->window(), &proto, &num_return)) {
2002-12-01 13:42:15 +00:00
for (int i = 0; i < num_return; ++i) {
2003-04-14 15:01:55 +00:00
if (proto[i] == fbatoms->getWMDeleteAtom())
functions.close = true;
2003-04-14 15:01:55 +00:00
else if (proto[i] == fbatoms->getWMTakeFocusAtom())
2002-12-01 13:42:15 +00:00
send_focus_message = true;
2003-04-14 15:01:55 +00:00
else if (proto[i] == fbatoms->getFluxboxStructureMessagesAtom())
2003-05-11 17:14:41 +00:00
screen().addNetizen(m_client->window());
2002-12-01 13:42:15 +00:00
}
XFree(proto);
} else {
2003-04-14 15:01:55 +00:00
cerr<<"Warning: Failed to read WM Protocols. "<<endl;
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::getWMHints() {
2003-04-14 15:01:55 +00:00
//!!
XWMHints *wmhint = XGetWMHints(display, m_client->window());
2002-12-01 13:42:15 +00:00
if (! wmhint) {
iconic = false;
2003-05-10 16:53:09 +00:00
m_focus_mode = F_PASSIVE;
2003-04-14 15:01:55 +00:00
m_client->window_group = None;
m_client->initial_state = NormalState;
2002-12-01 13:42:15 +00:00
} else {
2003-04-14 15:01:55 +00:00
m_client->wm_hint_flags = wmhint->flags;
2002-12-01 13:42:15 +00:00
if (wmhint->flags & InputHint) {
if (wmhint->input) {
if (send_focus_message)
2003-05-10 16:53:09 +00:00
m_focus_mode = F_LOCALLYACTIVE;
2002-12-01 13:42:15 +00:00
else
2003-05-10 16:53:09 +00:00
m_focus_mode = F_PASSIVE;
2002-12-01 13:42:15 +00:00
} else {
if (send_focus_message)
2003-05-10 16:53:09 +00:00
m_focus_mode = F_GLOBALLYACTIVE;
2002-12-01 13:42:15 +00:00
else
2003-05-10 16:53:09 +00:00
m_focus_mode = F_NOINPUT;
2002-12-01 13:42:15 +00:00
}
} else
2003-05-10 16:53:09 +00:00
m_focus_mode = F_PASSIVE;
2002-12-01 13:42:15 +00:00
if (wmhint->flags & StateHint)
2003-04-14 15:01:55 +00:00
m_client->initial_state = wmhint->initial_state;
2002-12-01 13:42:15 +00:00
else
2003-04-14 15:01:55 +00:00
m_client->initial_state = NormalState;
2002-12-01 13:42:15 +00:00
if (wmhint->flags & WindowGroupHint) {
2003-04-14 15:01:55 +00:00
if (! m_client->window_group) {
m_client->window_group = wmhint->window_group;
Fluxbox::instance()->saveGroupSearch(m_client->window_group, this);
2002-12-01 13:42:15 +00:00
}
} else
2003-04-14 15:01:55 +00:00
m_client->window_group = None;
2002-12-01 13:42:15 +00:00
XFree(wmhint);
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::getWMNormalHints() {
2002-12-01 13:42:15 +00:00
long icccm_mask;
XSizeHints sizehint;
2003-04-14 15:01:55 +00:00
if (! XGetWMNormalHints(display, m_client->window(), &sizehint, &icccm_mask)) {
m_client->min_width = m_client->min_height =
m_client->base_width = m_client->base_height =
m_client->width_inc = m_client->height_inc = 1;
m_client->max_width = 0; // unbounded
m_client->max_height = 0;
m_client->min_aspect_x = m_client->min_aspect_y =
m_client->max_aspect_x = m_client->max_aspect_y = 1;
m_client->win_gravity = NorthWestGravity;
2002-12-01 13:42:15 +00:00
} else {
2003-04-14 15:01:55 +00:00
m_client->normal_hint_flags = sizehint.flags;
2002-12-01 13:42:15 +00:00
if (sizehint.flags & PMinSize) {
2003-04-14 15:01:55 +00:00
m_client->min_width = sizehint.min_width;
m_client->min_height = sizehint.min_height;
2002-12-01 13:42:15 +00:00
} else
2003-04-14 15:01:55 +00:00
m_client->min_width = m_client->min_height = 1;
2002-12-01 13:42:15 +00:00
if (sizehint.flags & PMaxSize) {
2003-04-14 15:01:55 +00:00
m_client->max_width = sizehint.max_width;
m_client->max_height = sizehint.max_height;
2002-12-01 13:42:15 +00:00
} else {
2003-04-14 15:01:55 +00:00
m_client->max_width = 0; // unbounded
m_client->max_height = 0;
2002-12-01 13:42:15 +00:00
}
if (sizehint.flags & PResizeInc) {
2003-04-14 15:01:55 +00:00
m_client->width_inc = sizehint.width_inc;
m_client->height_inc = sizehint.height_inc;
2002-12-01 13:42:15 +00:00
} else
2003-04-14 15:01:55 +00:00
m_client->width_inc = m_client->height_inc = 1;
2002-12-01 13:42:15 +00:00
if (sizehint.flags & PAspect) {
2003-04-14 15:01:55 +00:00
m_client->min_aspect_x = sizehint.min_aspect.x;
m_client->min_aspect_y = sizehint.min_aspect.y;
m_client->max_aspect_x = sizehint.max_aspect.x;
m_client->max_aspect_y = sizehint.max_aspect.y;
2002-12-01 13:42:15 +00:00
} else
2003-04-14 15:01:55 +00:00
m_client->min_aspect_x = m_client->min_aspect_y =
m_client->max_aspect_x = m_client->max_aspect_y = 1;
2002-12-01 13:42:15 +00:00
if (sizehint.flags & PBaseSize) {
2003-04-14 15:01:55 +00:00
m_client->base_width = sizehint.base_width;
m_client->base_height = sizehint.base_height;
2002-12-01 13:42:15 +00:00
} else
2003-04-14 15:01:55 +00:00
m_client->base_width = m_client->base_height = 0;
2002-12-01 13:42:15 +00:00
if (sizehint.flags & PWinGravity)
2003-04-14 15:01:55 +00:00
m_client->win_gravity = sizehint.win_gravity;
2002-12-01 13:42:15 +00:00
else
2003-04-14 15:01:55 +00:00
m_client->win_gravity = NorthWestGravity;
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::getMWMHints() {
2002-12-01 13:42:15 +00:00
int format;
Atom atom_return;
unsigned long num, len;
2003-04-15 12:22:52 +00:00
Atom motif_wm_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False);
2003-05-19 22:43:48 +00:00
if (!m_client->property(motif_wm_hints, 0,
2002-12-01 13:42:15 +00:00
PropMwmHintsElements, false,
2003-04-15 12:22:52 +00:00
motif_wm_hints, &atom_return,
2002-12-01 13:42:15 +00:00
&format, &num, &len,
2003-04-14 15:01:55 +00:00
(unsigned char **) &m_client->mwm_hint) == Success &&
m_client->mwm_hint) {
2002-12-01 13:42:15 +00:00
return;
}
2003-05-15 11:17:29 +00:00
if (num != static_cast<unsigned int>(PropMwmHintsElements))
2002-12-01 13:42:15 +00:00
return;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->flags & MwmHintsDecorations) {
if (m_client->mwm_hint->decorations & MwmDecorAll) {
2002-12-01 13:42:15 +00:00
decorations.titlebar = decorations.handle = decorations.border =
decorations.iconify = decorations.maximize =
decorations.close = decorations.menu = true;
} else {
decorations.titlebar = decorations.handle = decorations.border =
decorations.iconify = decorations.maximize =
decorations.close = decorations.tab = false;
decorations.menu = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->decorations & MwmDecorBorder)
2002-12-01 13:42:15 +00:00
decorations.border = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->decorations & MwmDecorHandle)
2002-12-01 13:42:15 +00:00
decorations.handle = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->decorations & MwmDecorTitle) {
//only tab on windows with titlebar
decorations.titlebar = decorations.tab = true;
}
if (m_client->mwm_hint->decorations & MwmDecorMenu)
2002-12-01 13:42:15 +00:00
decorations.menu = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->decorations & MwmDecorIconify)
2002-12-01 13:42:15 +00:00
decorations.iconify = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->decorations & MwmDecorMaximize)
2002-12-01 13:42:15 +00:00
decorations.maximize = true;
}
}
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->flags & MwmHintsFunctions) {
if (m_client->mwm_hint->functions & MwmFuncAll) {
2002-12-01 13:42:15 +00:00
functions.resize = functions.move = functions.iconify =
functions.maximize = functions.close = true;
} else {
functions.resize = functions.move = functions.iconify =
functions.maximize = functions.close = false;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->functions & MwmFuncResize)
2002-12-01 13:42:15 +00:00
functions.resize = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->functions & MwmFuncMove)
2002-12-01 13:42:15 +00:00
functions.move = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->functions & MwmFuncIconify)
2002-12-01 13:42:15 +00:00
functions.iconify = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->functions & MwmFuncMaximize)
2002-12-01 13:42:15 +00:00
functions.maximize = true;
2003-04-14 15:01:55 +00:00
if (m_client->mwm_hint->functions & MwmFuncClose)
2002-12-01 13:42:15 +00:00
functions.close = true;
}
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::getBlackboxHints() {
2002-12-01 13:42:15 +00:00
int format;
Atom atom_return;
unsigned long num, len;
FbAtoms *atoms = FbAtoms::instance();
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
if (XGetWindowProperty(display, m_client->window(),
atoms->getFluxboxHintsAtom(), 0,
2002-12-01 13:42:15 +00:00
PropBlackboxHintsElements, False,
atoms->getFluxboxHintsAtom(), &atom_return,
2002-12-01 13:42:15 +00:00
&format, &num, &len,
2003-04-14 15:01:55 +00:00
(unsigned char **) &m_client->blackbox_hint) == Success &&
m_client->blackbox_hint) {
2002-12-01 13:42:15 +00:00
2003-05-10 14:27:57 +00:00
if (num == (unsigned)PropBlackboxHintsElements) {
if (m_client->blackbox_hint->flags & ATTRIB_SHADED)
shaded = (m_client->blackbox_hint->attrib & ATTRIB_SHADED);
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if ((m_client->blackbox_hint->flags & ATTRIB_MAXHORIZ) &&
(m_client->blackbox_hint->flags & ATTRIB_MAXVERT))
2003-04-14 15:01:55 +00:00
maximized = ((m_client->blackbox_hint->attrib &
2003-05-10 14:27:57 +00:00
(ATTRIB_MAXHORIZ |
ATTRIB_MAXVERT)) ? 1 : 0);
else if (m_client->blackbox_hint->flags & ATTRIB_MAXVERT)
2003-04-14 15:01:55 +00:00
maximized = ((m_client->blackbox_hint->attrib &
2003-05-10 14:27:57 +00:00
ATTRIB_MAXVERT) ? 2 : 0);
else if (m_client->blackbox_hint->flags & ATTRIB_MAXHORIZ)
2003-04-14 15:01:55 +00:00
maximized = ((m_client->blackbox_hint->attrib &
2003-05-10 14:27:57 +00:00
ATTRIB_MAXHORIZ) ? 3 : 0);
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if (m_client->blackbox_hint->flags & ATTRIB_OMNIPRESENT)
2003-04-14 15:01:55 +00:00
stuck = (m_client->blackbox_hint->attrib &
2003-05-10 14:27:57 +00:00
ATTRIB_OMNIPRESENT);
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if (m_client->blackbox_hint->flags & ATTRIB_WORKSPACE)
2003-05-10 16:53:09 +00:00
m_workspace_number = m_client->blackbox_hint->workspace;
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if (m_client->blackbox_hint->flags & ATTRIB_STACK)
2003-05-10 16:53:09 +00:00
m_workspace_number = m_client->blackbox_hint->stack;
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if (m_client->blackbox_hint->flags & ATTRIB_DECORATION) {
2003-05-10 16:53:09 +00:00
m_old_decoration = static_cast<Decoration>(m_client->blackbox_hint->decoration);
setDecoration(m_old_decoration);
2002-12-01 13:42:15 +00:00
}
}
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::move(int x, int y) {
2003-05-15 11:17:29 +00:00
moveResize(x, y, frame().width(), frame().height());
}
2001-12-11 20:47:02 +00:00
void FluxboxWindow::resize(unsigned int width, unsigned int height) {
2003-05-15 11:17:29 +00:00
moveResize(frame().x(), frame().y(), width, height);
}
2002-08-14 22:52:06 +00:00
void FluxboxWindow::moveResize(int new_x, int new_y,
unsigned int new_width, unsigned int new_height) {
2002-02-04 06:53:14 +00:00
2003-05-15 11:17:29 +00:00
bool send_event = (frame().x() != new_x || frame().y() != new_y);
2001-12-11 20:47:02 +00:00
2003-05-15 11:17:29 +00:00
if (new_width != frame().width() || new_height != frame().height()) {
if ((((signed) frame().width()) + new_x) < 0)
new_x = 0;
2003-05-15 11:17:29 +00:00
if ((((signed) frame().height()) + new_y) < 0)
new_y = 0;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
downsize();
2001-12-11 20:47:02 +00:00
2003-05-15 11:17:29 +00:00
frame().moveResize(new_x, new_y, new_width, new_height);
2002-12-01 13:42:15 +00:00
setFocusFlag(focused);
shaded = false;
send_event = true;
2002-12-01 13:42:15 +00:00
} else {
2003-05-15 11:17:29 +00:00
frame().move(new_x, new_y);
2001-12-11 20:47:02 +00:00
send_event = true;
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
if (send_event && ! moving) {
sendConfigureNotify();
2002-12-01 13:42:15 +00:00
}
2003-05-14 14:43:06 +00:00
shape();
}
2001-12-11 20:47:02 +00:00
bool FluxboxWindow::setInputFocus() {
2002-12-01 13:42:15 +00:00
//TODO hint skip focus
2003-05-15 11:17:29 +00:00
if (((signed) (frame().x() + frame().width())) < 0) {
if (((signed) (frame().y() + frame().height())) < 0) {
2003-05-10 16:53:09 +00:00
moveResize(screen().rootTheme().borderWidth(), screen().rootTheme().borderWidth(),
2003-05-15 11:17:29 +00:00
frame().width(), frame().height());
2003-05-15 12:00:46 +00:00
} else if (frame().y() > (signed) screen().height()) {
moveResize(screen().rootTheme().borderWidth(), screen().height() - frame().height(),
2003-05-15 11:17:29 +00:00
frame().width(), frame().height());
} else {
2003-05-15 11:17:29 +00:00
moveResize(screen().rootTheme().borderWidth(), frame().y() + screen().rootTheme().borderWidth(),
frame().width(), frame().height());
}
2003-05-15 12:00:46 +00:00
} else if (frame().x() > (signed) screen().width()) {
2003-05-15 11:17:29 +00:00
if (((signed) (frame().y() + frame().height())) < 0) {
2003-05-15 12:00:46 +00:00
moveResize(screen().width() - frame().width(), screen().rootTheme().borderWidth(),
2003-05-15 11:17:29 +00:00
frame().width(), frame().height());
2003-05-15 12:00:46 +00:00
} else if (frame().y() > (signed) screen().height()) {
moveResize(screen().width() - frame().width(),
screen().height() - frame().height(),
2003-05-15 11:17:29 +00:00
frame().width(), frame().height());
} else {
2003-05-15 12:00:46 +00:00
moveResize(screen().width() - frame().width(),
2003-05-15 11:17:29 +00:00
frame().y() + screen().rootTheme().borderWidth(),
frame().width(), frame().height());
}
2002-12-01 13:42:15 +00:00
}
if (! validateClient())
return false;
bool ret = false;
if (!m_client->transients.empty() && m_client->isModal()) {
WinClient::TransientList::iterator it = m_client->transients.begin();
WinClient::TransientList::iterator it_end = m_client->transients.end();
2002-12-01 13:42:15 +00:00
for (; it != it_end; ++it) {
if ((*it)->isModal())
2003-05-11 15:32:23 +00:00
return (*it)->fbwindow()->setCurrentClient(**it, true);
2002-12-01 13:42:15 +00:00
}
} else {
2003-05-10 16:53:09 +00:00
if (m_focus_mode == F_LOCALLYACTIVE || m_focus_mode == F_PASSIVE) {
2003-04-14 15:01:55 +00:00
XSetInputFocus(display, m_client->window(),
2002-12-01 13:42:15 +00:00
RevertToPointerRoot, CurrentTime);
} else {
return false;
}
2003-05-10 16:53:09 +00:00
screen().setFocusedWindow(*m_client);
2003-04-14 15:01:55 +00:00
Fluxbox::instance()->setFocusedWindow(this);
2003-05-01 13:19:36 +00:00
2003-05-15 11:17:29 +00:00
frame().setFocus(true);
2003-05-11 15:32:23 +00:00
2003-04-14 15:01:55 +00:00
if (send_focus_message)
m_client->sendFocus();
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if ((screen().isSloppyFocus() || screen().isSemiSloppyFocus())
&& screen().doAutoRaise())
m_timer.start();
2002-12-01 13:42:15 +00:00
ret = true;
}
return ret;
2001-12-11 20:47:02 +00:00
}
2003-02-16 17:57:54 +00:00
void FluxboxWindow::hide() {
2003-04-14 15:01:55 +00:00
#ifdef DEBUG
cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"]"<<endl;
#endif // DEBUG
2003-02-16 17:57:54 +00:00
m_windowmenu.hide();
2003-05-15 11:17:29 +00:00
frame().hide();
2003-02-16 17:57:54 +00:00
}
void FluxboxWindow::show() {
2003-05-15 11:17:29 +00:00
frame().show();
2003-02-16 17:57:54 +00:00
}
/**
Unmaps the window and removes it from workspace list
*/
void FluxboxWindow::iconify() {
2003-04-14 15:01:55 +00:00
if (isIconic()) // no need to iconify if we're already
2002-12-01 13:42:15 +00:00
return;
2001-12-11 20:47:02 +00:00
m_windowmenu.hide();
2002-12-01 13:42:15 +00:00
iconic = true;
2003-04-14 15:01:55 +00:00
2003-03-03 21:51:13 +00:00
setState(IconicState);
2003-05-15 11:17:29 +00:00
frame().hide();
2003-03-03 21:51:13 +00:00
2003-04-14 15:01:55 +00:00
ClientList::iterator client_it = m_clientlist.begin();
const ClientList::iterator client_it_end = m_clientlist.end();
for (; client_it != client_it_end; ++client_it) {
WinClient &client = *(*client_it);
client.setEventMask(NoEventMask);
client.hide();
client.setEventMask(PropertyChangeMask | StructureNotifyMask | FocusChangeMask);
if (client.transientFor() &&
client.transientFor()->fbwindow()) {
if (!client.transientFor()->fbwindow()->isIconic()) {
client.transientFor()->fbwindow()->iconify();
}
2003-04-14 15:01:55 +00:00
}
2001-12-11 20:47:02 +00:00
if (!client.transientList().empty()) {
WinClient::TransientList::iterator it = client.transientList().begin();
WinClient::TransientList::iterator it_end = client.transientList().end();
for (; it != it_end; it++)
if ((*it)->fbwindow())
(*it)->fbwindow()->iconify();
2002-12-01 13:42:15 +00:00
}
}
2003-05-13 11:14:05 +00:00
if (Fluxbox::instance()->getFocusedWindow() == this)
Fluxbox::instance()->revertFocus(screen());
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::deiconify(bool reassoc, bool do_raise) {
if (oplock) return;
oplock = true;
2002-12-01 13:42:15 +00:00
if (iconic || reassoc) {
2003-05-15 12:00:46 +00:00
screen().reassociateWindow(this, screen().currentWorkspace()->workspaceID(), false);
} else if (moving || m_workspace_number != screen().currentWorkspace()->workspaceID()) {
2003-05-11 23:44:09 +00:00
oplock = false;
2002-12-01 13:42:15 +00:00
return;
2003-05-11 23:44:09 +00:00
}
2002-12-01 13:42:15 +00:00
2003-03-03 21:51:13 +00:00
bool was_iconic = iconic;
iconic = false;
2002-12-01 13:42:15 +00:00
setState(NormalState);
2003-04-14 15:01:55 +00:00
ClientList::iterator client_it = clientList().begin();
ClientList::iterator client_it_end = clientList().end();
for (; client_it != client_it_end; ++client_it) {
(*client_it)->setEventMask(NoEventMask);
(*client_it)->show();
(*client_it)->setEventMask(PropertyChangeMask | StructureNotifyMask | FocusChangeMask);
}
2003-05-11 23:44:09 +00:00
2003-05-15 11:17:29 +00:00
frame().show();
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if (was_iconic && screen().doFocusNew())
2002-12-01 13:42:15 +00:00
setInputFocus();
2003-05-15 11:17:29 +00:00
if (focused != frame().focused())
frame().setFocus(focused);
2002-12-01 13:42:15 +00:00
if (reassoc && !m_client->transients.empty()) {
2002-12-01 13:42:15 +00:00
// deiconify all transients
2003-04-14 15:01:55 +00:00
client_it = clientList().begin();
for (; client_it != client_it_end; ++client_it) {
//TODO: Can this get stuck in a loop?
WinClient::TransientList::iterator trans_it =
2003-04-14 15:01:55 +00:00
(*client_it)->transientList().begin();
WinClient::TransientList::iterator trans_it_end =
2003-04-14 15:01:55 +00:00
(*client_it)->transientList().end();
for (; trans_it != trans_it_end; ++trans_it) {
if ((*trans_it)->fbwindow())
(*trans_it)->fbwindow()->deiconify(true, false);
}
2002-12-01 13:42:15 +00:00
}
}
oplock = false;
if (do_raise)
raise();
2001-12-11 20:47:02 +00:00
}
/**
Send close request to client window
*/
void FluxboxWindow::close() {
2003-04-14 15:01:55 +00:00
#ifdef DEBUG
cerr<<__FILE__<<"("<<__FUNCTION__<<")"<<endl;
#endif // DEBUG
m_client->sendClose();
2001-12-11 20:47:02 +00:00
}
/**
Set window in withdrawn state
*/
void FluxboxWindow::withdraw() {
2002-12-01 13:42:15 +00:00
iconic = false;
2002-12-01 13:42:15 +00:00
if (isResizing())
stopResizing();
2002-02-17 18:48:22 +00:00
2003-05-15 11:17:29 +00:00
frame().hide();
2001-12-11 20:47:02 +00:00
m_windowmenu.hide();
2001-12-11 20:47:02 +00:00
}
/**
Maximize window both horizontal and vertical
*/
void FluxboxWindow::maximize() {
2002-12-01 13:42:15 +00:00
if (isIconic())
deiconify();
2002-08-12 03:28:17 +00:00
if (!maximized) {
// save old values
int head = screen().getHead(frame().window());
m_old_width = frame().width();
m_old_height = frame().height();
m_old_pos_x = frame().x();
m_old_pos_y = frame().y();
unsigned int left_x = screen().maxLeft(head);
unsigned int max_width = screen().maxRight(head);
unsigned int max_top = screen().maxTop(head);
moveResize(left_x, max_top,
2003-05-19 15:32:47 +00:00
max_width - left_x - 2*frame().window().borderWidth(),
screen().maxBottom(head) - max_top - 2*frame().window().borderWidth());
} else { // demaximize, restore to old values
moveResize(m_old_pos_x, m_old_pos_y,
m_old_width, m_old_height);
}
// toggle maximize
maximized = !maximized;
}
2002-12-01 13:42:15 +00:00
void FluxboxWindow::maximizeHorizontal() {
int head = screen().getHead(frame().window());
unsigned int left_x = screen().maxLeft(head);
unsigned int max_width = screen().maxRight(head);
2003-05-15 11:17:29 +00:00
moveResize(left_x, frame().y(),
2003-05-19 15:39:06 +00:00
max_width - left_x - 2*frame().window().borderWidth(), frame().height());
2002-12-01 13:42:15 +00:00
}
2002-12-01 13:42:15 +00:00
/**
Maximize window horizontal
*/
void FluxboxWindow::maximizeVertical() {
int head = screen().getHead(frame().window());
unsigned int max_top = screen().maxTop(head);
2003-05-15 11:17:29 +00:00
moveResize(frame().x(), max_top,
2003-05-19 15:39:06 +00:00
frame().width(),
screen().maxBottom(head) - max_top - 2*frame().window().borderWidth());
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::setWorkspace(int n) {
2003-02-16 17:57:54 +00:00
2003-05-10 16:53:09 +00:00
m_workspace_number = n;
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags |= ATTRIB_WORKSPACE;
m_blackbox_attrib.workspace = m_workspace_number;
2002-09-07 20:16:43 +00:00
2002-12-01 13:42:15 +00:00
// notify workspace change
2002-09-07 20:16:43 +00:00
#ifdef DEBUG
2002-12-01 13:42:15 +00:00
cerr<<this<<" notify workspace signal"<<endl;
2002-09-07 20:16:43 +00:00
#endif // DEBUG
2002-12-01 13:42:15 +00:00
m_workspacesig.notify();
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::setLayerNum(int layernum) {
m_layernum = layernum;
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags |= ATTRIB_STACK;
m_blackbox_attrib.stack = layernum;
saveBlackboxHints();
#ifdef DEBUG
cerr<<this<<" notify layer signal"<<endl;
#endif // DEBUG
m_layersig.notify();
}
2001-12-11 20:47:02 +00:00
void FluxboxWindow::shade() {
2003-04-14 15:01:55 +00:00
// we can only shade if we have a titlebar
2003-02-17 09:56:00 +00:00
if (!decorations.titlebar)
return;
2003-05-15 11:17:29 +00:00
frame().shade();
2002-12-01 13:42:15 +00:00
2003-02-17 09:56:00 +00:00
if (shaded) {
shaded = false;
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags ^= ATTRIB_SHADED;
m_blackbox_attrib.attrib ^= ATTRIB_SHADED;
2002-12-01 13:42:15 +00:00
2003-02-17 09:56:00 +00:00
setState(NormalState);
} else {
shaded = true;
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags |= ATTRIB_SHADED;
m_blackbox_attrib.attrib |= ATTRIB_SHADED;
2003-04-14 15:01:55 +00:00
// shading is the same as iconic
2003-02-17 09:56:00 +00:00
setState(IconicState);
2002-12-01 13:42:15 +00:00
}
2003-02-17 09:56:00 +00:00
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::stick() {
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
if (stuck) {
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags ^= ATTRIB_OMNIPRESENT;
m_blackbox_attrib.attrib ^= ATTRIB_OMNIPRESENT;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
stuck = false;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
} else {
stuck = true;
2003-04-14 15:01:55 +00:00
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags |= ATTRIB_OMNIPRESENT;
m_blackbox_attrib.attrib |= ATTRIB_OMNIPRESENT;
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
2003-05-10 16:53:09 +00:00
setState(m_current_state);
}
2003-02-19 14:53:38 +00:00
2003-02-09 14:11:14 +00:00
void FluxboxWindow::raise() {
if (isIconic())
deiconify();
2003-02-19 14:53:38 +00:00
// get root window
WinClient *client = getRootTransientFor(m_client);
2003-02-19 14:53:38 +00:00
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
2003-02-09 14:11:14 +00:00
2003-02-19 14:53:38 +00:00
// raise this window and every transient in it
if (client->fbwindow())
raiseFluxboxWindow(*client->fbwindow());
2001-12-11 20:47:02 +00:00
}
2003-02-09 14:11:14 +00:00
void FluxboxWindow::lower() {
if (isIconic())
deiconify();
2003-02-09 14:11:14 +00:00
// get root window
WinClient *client = getRootTransientFor(m_client);
2003-02-19 14:53:38 +00:00
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
2003-02-09 14:11:14 +00:00
if (client->fbwindow())
lowerFluxboxWindow(*client->fbwindow());
}
2001-12-11 20:47:02 +00:00
void FluxboxWindow::tempRaise() {
if (isIconic())
deiconify();
// get root window
WinClient *client = getRootTransientFor(m_client);
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
if (client->fbwindow())
tempRaiseFluxboxWindow(*client->fbwindow());
}
2003-02-09 14:11:14 +00:00
void FluxboxWindow::raiseLayer() {
// don't let it up to menu layer
2003-05-15 11:17:29 +00:00
if (layerNum() == (Fluxbox::instance()->getMenuLayer()+1))
2003-02-09 14:11:14 +00:00
return;
// get root window
WinClient *client = getRootTransientFor(m_client);
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
2003-02-09 14:11:14 +00:00
FluxboxWindow *win = client->fbwindow();
if (!win) return;
if (!win->isIconic())
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowRaise(client->window());
2003-05-15 11:17:29 +00:00
win->layerItem().raiseLayer();
// remember number just in case a transient happens to revisit this window
2003-05-15 11:17:29 +00:00
int layer_num = win->layerItem().getLayerNum();
win->setLayerNum(layer_num);
2003-02-09 14:11:14 +00:00
WinClient::TransientList::const_iterator it = client->transientList().begin();
WinClient::TransientList::const_iterator it_end = client->transientList().end();
2003-02-09 14:11:14 +00:00
for (; it != it_end; ++it) {
win = (*it)->fbwindow();
if (win && !win->isIconic()) {
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowRaise((*it)->window());
2003-05-15 11:17:29 +00:00
win->layerItem().moveToLayer(layer_num);
win->setLayerNum(layer_num);
2003-02-09 14:11:14 +00:00
}
}
}
void FluxboxWindow::lowerLayer() {
// get root window
WinClient *client = getRootTransientFor(m_client);
2003-02-09 14:11:14 +00:00
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
FluxboxWindow *win = client->fbwindow();
if (!win) return;
2003-02-09 14:11:14 +00:00
if (!win->isIconic()) {
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowLower(client->window());
2003-02-09 14:11:14 +00:00
}
2003-05-15 11:17:29 +00:00
win->layerItem().lowerLayer();
// remember number just in case a transient happens to revisit this window
2003-05-15 11:17:29 +00:00
int layer_num = win->layerItem().getLayerNum();
win->setLayerNum(layer_num);
WinClient::TransientList::const_iterator it = client->transientList().begin();
WinClient::TransientList::const_iterator it_end = client->transientList().end();
2003-02-09 14:11:14 +00:00
for (; it != it_end; ++it) {
win = (*it)->fbwindow();
if (win && !win->isIconic()) {
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowLower((*it)->window());
2003-05-15 11:17:29 +00:00
win->layerItem().moveToLayer(layer_num);
win->setLayerNum(layer_num);
2003-02-09 14:11:14 +00:00
}
}
}
2003-02-09 14:11:14 +00:00
void FluxboxWindow::moveToLayer(int layernum) {
Fluxbox * fluxbox = Fluxbox::instance();
// don't let it set its layer into menu area
if (layernum <= fluxbox->getMenuLayer()) {
layernum = fluxbox->getMenuLayer() + 1;
}
// get root window
WinClient *client = getRootTransientFor(m_client);
// if we don't have any root window use this as root
if (client == 0)
client = m_client;
FluxboxWindow *win = client->fbwindow();
if (!win) return;
2003-02-09 14:11:14 +00:00
if (!win->isIconic()) {
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowRaise(client->window());
2003-02-09 14:11:14 +00:00
}
2003-05-15 11:17:29 +00:00
win->layerItem().moveToLayer(layernum);
// remember number just in case a transient happens to revisit this window
2003-05-15 11:17:29 +00:00
layernum = win->layerItem().getLayerNum();
win->setLayerNum(layernum);
WinClient::TransientList::const_iterator it = client->transientList().begin();
WinClient::TransientList::const_iterator it_end = client->transientList().end();
2003-02-09 14:11:14 +00:00
for (; it != it_end; ++it) {
win = (*it)->fbwindow();
if (win && !win->isIconic()) {
2003-05-10 16:53:09 +00:00
screen().updateNetizenWindowRaise((*it)->window());
2003-05-15 11:17:29 +00:00
win->layerItem().moveToLayer(layernum);
win->setLayerNum(layernum);
2003-02-09 14:11:14 +00:00
}
}
}
2001-12-11 20:47:02 +00:00
void FluxboxWindow::setFocusFlag(bool focus) {
2002-12-01 13:42:15 +00:00
focused = focus;
2003-04-14 15:01:55 +00:00
// Record focus timestamp for window cycling enhancements
2002-12-01 13:42:15 +00:00
if (focused)
2003-05-10 16:53:09 +00:00
gettimeofday(&m_last_focus_time, 0);
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
frame().setFocus(focus);
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if ((screen().isSloppyFocus() || screen().isSemiSloppyFocus()) &&
screen().doAutoRaise())
m_timer.stop();
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::installColormap(bool install) {
2002-12-01 13:42:15 +00:00
Fluxbox *fluxbox = Fluxbox::instance();
fluxbox->grab();
if (! validateClient()) return;
int i = 0, ncmap = 0;
2003-04-14 15:01:55 +00:00
Colormap *cmaps = XListInstalledColormaps(display, m_client->window(), &ncmap);
2002-12-01 13:42:15 +00:00
XWindowAttributes wattrib;
2003-04-14 15:01:55 +00:00
if (cmaps) { //!!
2003-04-15 12:22:52 +00:00
if (m_client->getAttrib(wattrib)) {
2002-12-01 13:42:15 +00:00
if (install) {
// install the window's colormap
2002-12-01 13:42:15 +00:00
for (i = 0; i < ncmap; i++) {
if (*(cmaps + i) == wattrib.colormap) {
// this window is using an installed color map... do not install
install = false;
break; //end for-loop (we dont need to check more)
}
}
// otherwise, install the window's colormap
2002-12-01 13:42:15 +00:00
if (install)
XInstallColormap(display, wattrib.colormap);
} else {
2003-04-14 15:01:55 +00:00
for (i = 0; i < ncmap; i++) { // uninstall the window's colormap
if (*(cmaps + i) == wattrib.colormap)
XUninstallColormap(display, wattrib.colormap);
}
2002-12-01 13:42:15 +00:00
}
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
XFree(cmaps);
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
fluxbox->ungrab();
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
/**
Saves blackbox hints for every client in our list
*/
void FluxboxWindow::saveBlackboxHints() {
2003-04-14 15:01:55 +00:00
for_each(m_clientlist.begin(), m_clientlist.end(),
FbTk::ChangeProperty(display, FbAtoms::instance()->getFluxboxAttributesAtom(),
PropModeReplace,
2003-05-10 16:53:09 +00:00
(unsigned char *)&m_blackbox_attrib,
2003-04-14 15:01:55 +00:00
PropBlackboxAttributesElements));
}
2003-04-14 15:01:55 +00:00
/**
Sets state on each client in our list
*/
2001-12-11 20:47:02 +00:00
void FluxboxWindow::setState(unsigned long new_state) {
2003-05-10 16:53:09 +00:00
m_current_state = new_state;
2002-12-01 13:42:15 +00:00
unsigned long state[2];
2003-05-10 16:53:09 +00:00
state[0] = (unsigned long) m_current_state;
2002-12-01 13:42:15 +00:00
state[1] = (unsigned long) None;
2003-04-14 15:01:55 +00:00
for_each(m_clientlist.begin(), m_clientlist.end(),
FbTk::ChangeProperty(display, FbAtoms::instance()->getWMStateAtom(),
PropModeReplace,
(unsigned char *)state, 2));
2001-12-11 20:47:02 +00:00
saveBlackboxHints();
2002-12-01 13:42:15 +00:00
//notify state changed
m_statesig.notify();
2001-12-11 20:47:02 +00:00
}
bool FluxboxWindow::getState() {
2003-05-10 16:53:09 +00:00
m_current_state = 0;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
Atom atom_return;
bool ret = false;
int foo;
unsigned long *state, ulfoo, nitems;
2003-04-15 12:22:52 +00:00
if ((XGetWindowProperty(display, m_client->window(), FbAtoms::instance()->getWMStateAtom(),
0l, 2l, false, FbAtoms::instance()->getWMStateAtom(),
2002-12-01 13:42:15 +00:00
&atom_return, &foo, &nitems, &ulfoo,
(unsigned char **) &state) != Success) ||
(! state)) {
return false;
}
if (nitems >= 1) {
2003-05-10 16:53:09 +00:00
m_current_state = static_cast<unsigned long>(state[0]);
2002-12-01 13:42:15 +00:00
ret = true;
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
XFree(static_cast<void *>(state));
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
return ret;
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
//!! TODO: this functions looks odd
void FluxboxWindow::setGravityOffsets() {
2003-05-15 11:17:29 +00:00
int newx = frame().x();
int newy = frame().y();
2002-12-01 13:42:15 +00:00
// translate x coordinate
2003-04-14 15:01:55 +00:00
switch (m_client->win_gravity) {
2002-12-01 13:42:15 +00:00
// handle Westward gravity
case NorthWestGravity:
case WestGravity:
case SouthWestGravity:
default:
#ifdef DEBUG
cerr<<__FILE__<<": Default gravity: SouthWest, NorthWest, West"<<endl;
#endif // DEBUG
2003-05-15 11:17:29 +00:00
newx = frame().x();
2002-12-01 13:42:15 +00:00
break;
// handle Eastward gravity
case NorthEastGravity:
case EastGravity:
case SouthEastGravity:
#ifdef DEBUG
cerr<<__FILE__<<": Gravity: SouthEast, NorthEast, East"<<endl;
#endif // DEBUG
2003-05-15 11:17:29 +00:00
newx = frame().x() + frame().clientArea().width() - frame().width();
2002-12-01 13:42:15 +00:00
break;
// no x translation desired - default
case StaticGravity:
case ForgetGravity:
case CenterGravity:
#ifdef DEBUG
cerr<<__FILE__<<": Gravity: Center, Forget, Static"<<endl;
#endif // DEBUG
2003-05-15 11:17:29 +00:00
newx = frame().x();
2002-12-01 13:42:15 +00:00
}
// translate y coordinate
2003-04-14 15:01:55 +00:00
switch (m_client->win_gravity) {
2002-12-01 13:42:15 +00:00
// handle Northbound gravity
case NorthWestGravity:
case NorthGravity:
case NorthEastGravity:
default:
2003-05-15 11:17:29 +00:00
newy = frame().y();
2002-12-01 13:42:15 +00:00
break;
// handle Southbound gravity
case SouthWestGravity:
case SouthGravity:
case SouthEastGravity:
2003-05-15 11:17:29 +00:00
newy = frame().y() + frame().clientArea().height() - frame().height();
2002-12-01 13:42:15 +00:00
break;
// no y translation desired - default
case StaticGravity:
case ForgetGravity:
case CenterGravity:
2003-05-15 11:17:29 +00:00
newy = frame().y();
2002-12-01 13:42:15 +00:00
break;
}
// finaly move the frame
2003-05-15 11:17:29 +00:00
if (frame().x() != newx || frame().y() != newy)
frame().move(newx, newy);
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
/**
* Sets the attributes to what they should be
* but doesn't change the actual state
* (so the caller can set defaults etc as well)
*/
2003-02-16 17:57:54 +00:00
void FluxboxWindow::restoreAttributes() {
2002-12-01 13:42:15 +00:00
if (!getState())
2003-05-10 16:53:09 +00:00
m_current_state = NormalState;
2002-12-01 13:42:15 +00:00
Atom atom_return;
int foo;
unsigned long ulfoo, nitems;
2003-04-15 12:22:52 +00:00
FbAtoms *fbatoms = FbAtoms::instance();
2002-12-01 13:42:15 +00:00
2003-05-10 14:27:57 +00:00
BlackboxAttributes *net;
2003-05-19 22:43:48 +00:00
if (m_client->property(fbatoms->getFluxboxAttributesAtom(), 0l,
2002-12-01 13:42:15 +00:00
PropBlackboxAttributesElements, false,
2003-04-15 12:22:52 +00:00
fbatoms->getFluxboxAttributesAtom(), &atom_return, &foo,
2003-05-19 22:43:48 +00:00
&nitems, &ulfoo, (unsigned char **) &net) &&
net && nitems == (unsigned)PropBlackboxAttributesElements) {
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.flags = net->flags;
m_blackbox_attrib.attrib = net->attrib;
m_blackbox_attrib.workspace = net->workspace;
m_blackbox_attrib.stack = net->stack;
m_blackbox_attrib.premax_x = net->premax_x;
m_blackbox_attrib.premax_y = net->premax_y;
m_blackbox_attrib.premax_w = net->premax_w;
m_blackbox_attrib.premax_h = net->premax_h;
2002-12-01 13:42:15 +00:00
XFree(static_cast<void *>(net));
} else
return;
2003-05-10 16:53:09 +00:00
if (m_blackbox_attrib.flags & ATTRIB_SHADED &&
m_blackbox_attrib.attrib & ATTRIB_SHADED) {
2002-12-01 13:42:15 +00:00
int save_state =
2003-05-10 16:53:09 +00:00
((m_current_state == IconicState) ? NormalState : m_current_state);
2002-12-01 13:42:15 +00:00
shaded = true;
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
m_current_state = save_state;
2002-12-01 13:42:15 +00:00
}
2003-05-15 12:00:46 +00:00
if (( m_blackbox_attrib.workspace != screen().currentWorkspaceID()) &&
2003-05-10 16:53:09 +00:00
( m_blackbox_attrib.workspace < screen().getCount())) {
m_workspace_number = m_blackbox_attrib.workspace;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if (m_current_state == NormalState) m_current_state = WithdrawnState;
} else if (m_current_state == WithdrawnState)
m_current_state = NormalState;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if (m_blackbox_attrib.flags & ATTRIB_OMNIPRESENT &&
m_blackbox_attrib.attrib & ATTRIB_OMNIPRESENT) {
stuck = true;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
m_current_state = NormalState;
2002-12-01 13:42:15 +00:00
}
2003-05-10 16:53:09 +00:00
if (m_blackbox_attrib.flags & ATTRIB_STACK) {
2003-02-22 18:28:32 +00:00
//!! TODO check value?
2003-05-10 16:53:09 +00:00
m_layernum = m_blackbox_attrib.stack;
}
2003-05-10 16:53:09 +00:00
if ((m_blackbox_attrib.flags & ATTRIB_MAXHORIZ) ||
(m_blackbox_attrib.flags & ATTRIB_MAXVERT)) {
int x = m_blackbox_attrib.premax_x, y = m_blackbox_attrib.premax_y;
unsigned int w = m_blackbox_attrib.premax_w, h = m_blackbox_attrib.premax_h;
2002-12-01 13:42:15 +00:00
maximized = false;
2003-05-10 16:53:09 +00:00
if ((m_blackbox_attrib.flags & ATTRIB_MAXHORIZ) &&
(m_blackbox_attrib.flags & ATTRIB_MAXVERT))
maximized = true;
2003-05-10 16:53:09 +00:00
else if (m_blackbox_attrib.flags & ATTRIB_MAXVERT)
maximizeVertical();
2003-05-10 16:53:09 +00:00
else if (m_blackbox_attrib.flags & ATTRIB_MAXHORIZ)
maximizeHorizontal();
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
m_blackbox_attrib.premax_x = x;
m_blackbox_attrib.premax_y = y;
m_blackbox_attrib.premax_w = w;
m_blackbox_attrib.premax_h = h;
2002-12-01 13:42:15 +00:00
}
2003-05-10 16:53:09 +00:00
setState(m_current_state);
2001-12-11 20:47:02 +00:00
}
/**
Show the window menu at pos mx, my
*/
2002-08-12 03:28:17 +00:00
void FluxboxWindow::showMenu(int mx, int my) {
m_windowmenu.move(mx, my);
m_windowmenu.show();
m_windowmenu.raise();
}
/**
Moves the menu to last button press position and shows it,
if it's already visible it'll be hidden
*/
void FluxboxWindow::popupMenu() {
if (m_windowmenu.isVisible()) {
m_windowmenu.hide();
2002-12-01 13:42:15 +00:00
return;
}
// move menu directly under titlebar
2003-05-15 11:17:29 +00:00
int diff_y = frame().titlebar().height() + frame().titlebar().borderWidth();
if (!decorations.titlebar) // if we don't have any titlebar
diff_y = 0;
2003-05-15 11:17:29 +00:00
m_windowmenu.move(m_last_button_x, frame().y() + diff_y);
m_windowmenu.show();
m_windowmenu.raise();
2002-08-12 03:28:17 +00:00
}
void FluxboxWindow::restoreGravity() {
2002-12-01 13:42:15 +00:00
// restore x coordinate
2003-04-14 15:01:55 +00:00
switch (m_client->win_gravity) {
2002-12-01 13:42:15 +00:00
// handle Westward gravity
case NorthWestGravity:
case WestGravity:
case SouthWestGravity:
default:
2003-05-15 11:17:29 +00:00
m_client->x = frame().x();
2002-12-01 13:42:15 +00:00
break;
// handle Eastward gravity
2002-12-01 13:42:15 +00:00
case NorthEastGravity:
case EastGravity:
case SouthEastGravity:
2003-05-15 11:17:29 +00:00
m_client->x = (frame().x() + frame().width()) - m_client->width();
2002-12-01 13:42:15 +00:00
break;
}
// restore y coordinate
2003-04-14 15:01:55 +00:00
switch (m_client->win_gravity) {
2002-12-01 13:42:15 +00:00
// handle Northbound gravity
case NorthWestGravity:
case NorthGravity:
case NorthEastGravity:
default:
2003-05-15 11:17:29 +00:00
m_client->y = frame().y();
2002-12-01 13:42:15 +00:00
break;
// handle Southbound gravity
case SouthWestGravity:
case SouthGravity:
case SouthEastGravity:
2003-05-15 11:17:29 +00:00
m_client->y = (frame().y() + frame().height()) - m_client->height();
2002-12-01 13:42:15 +00:00
break;
}
2001-12-11 20:47:02 +00:00
}
/**
Determine if this is the lowest tab of them all
*/
bool FluxboxWindow::isLowerTab() const {
2003-04-14 15:01:55 +00:00
cerr<<__FILE__<<"("<<__FUNCTION__<<") TODO!"<<endl;
return true;
2002-03-18 19:58:06 +00:00
}
2001-12-11 20:47:02 +00:00
/**
Redirect any unhandled event to our handlers
*/
void FluxboxWindow::handleEvent(XEvent &event) {
switch (event.type) {
case ConfigureRequest:
configureRequestEvent(event.xconfigurerequest);
2003-04-15 12:31:53 +00:00
break;
case MapNotify:
mapNotifyEvent(event.xmap);
2003-04-15 12:31:53 +00:00
break;
// This is already handled in Fluxbox::handleEvent
// case MapRequest:
// mapRequestEvent(event.xmaprequest);
//break;
case PropertyNotify:
if (event.xproperty.state != PropertyDelete) {
propertyNotifyEvent(event.xproperty.atom);
}
break;
2003-05-14 14:43:06 +00:00
default:
2003-05-14 14:43:06 +00:00
#ifdef SHAPE
if (Fluxbox::instance()->haveShape() &&
event.type == Fluxbox::instance()->shapeEventbase() + ShapeNotify) {
XShapeEvent *shape_event = (XShapeEvent *)&event;
if (shape_event->kind != ShapeBounding)
break;
if (shape_event->shaped) {
m_shaped = true;
shape();
} else {
m_shaped = false;
// set no shape
Display *disp = FbTk::App::instance()->display();
XShapeCombineMask(disp,
2003-05-15 11:17:29 +00:00
frame().window().window(), ShapeBounding,
2003-05-14 14:43:06 +00:00
0, 0,
None, ShapeSet);
}
XSync(FbTk::App::instance()->display(), False);
break;
}
#endif // SHAPE
break;
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::mapRequestEvent(XMapRequestEvent &re) {
// we're only conserned about client window event
2003-05-11 15:32:23 +00:00
WinClient *client = findClient(re.window);
if (client == 0) {
#ifdef DEBUG
cerr<<"mapRequestEvent: Can't find client!"<<endl;
#endif // DEBUG
2002-12-01 13:42:15 +00:00
return;
2003-05-11 15:32:23 +00:00
}
2002-12-01 13:42:15 +00:00
Fluxbox *fluxbox = Fluxbox::instance();
bool get_state_ret = getState();
if (! (get_state_ret && fluxbox->isStartup())) {
2003-04-14 15:01:55 +00:00
if ((m_client->wm_hint_flags & StateHint) &&
2003-05-10 16:53:09 +00:00
(! (m_current_state == NormalState || m_current_state == IconicState))) {
m_current_state = m_client->initial_state;
2002-12-01 13:42:15 +00:00
} else
2003-05-10 16:53:09 +00:00
m_current_state = NormalState;
2002-12-01 13:42:15 +00:00
} else if (iconic)
2003-05-10 16:53:09 +00:00
m_current_state = NormalState;
2002-08-11 22:44:29 +00:00
2003-05-10 16:53:09 +00:00
switch (m_current_state) {
2002-12-01 13:42:15 +00:00
case IconicState:
iconify();
2002-08-11 22:44:29 +00:00
break;
2002-12-01 13:42:15 +00:00
case WithdrawnState:
withdraw();
2002-08-11 22:44:29 +00:00
break;
2002-12-01 13:42:15 +00:00
case NormalState:
// check WM_CLASS only when we changed state to NormalState from
2002-12-01 13:42:15 +00:00
// WithdrawnState (ICCC 4.1.2.5)
2002-08-11 22:44:29 +00:00
2002-12-01 13:42:15 +00:00
XClassHint ch;
2003-05-15 11:17:29 +00:00
if (XGetClassHint(display, client->window(), &ch) == 0) {
2002-12-01 13:42:15 +00:00
cerr<<"Failed to read class hint!"<<endl;
} else {
if (ch.res_name != 0) {
m_instance_name = const_cast<char *>(ch.res_name);
XFree(ch.res_name);
} else
m_instance_name = "";
if (ch.res_class != 0) {
m_class_name = const_cast<char *>(ch.res_class);
XFree(ch.res_class);
} else
m_class_name = "";
2003-04-14 15:01:55 +00:00
/*
2003-05-10 16:53:09 +00:00
Workspace *wsp = screen().getWorkspace(m_workspace_number);
2003-04-14 15:01:55 +00:00
// we must be resizable AND maximizable to be autogrouped
//!! TODO: there should be an isGroupable() function
if (wsp != 0 && isResizable() && isMaximizable()) {
wsp->checkGrouping(*this);
}
*/
2002-12-01 13:42:15 +00:00
}
2002-08-11 22:44:29 +00:00
2002-12-01 13:42:15 +00:00
deiconify(false);
2003-05-11 15:32:23 +00:00
2002-08-11 22:44:29 +00:00
break;
2002-12-01 13:42:15 +00:00
case InactiveState:
case ZoomState:
default:
deiconify(false);
break;
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::mapNotifyEvent(XMapEvent &ne) {
2003-04-15 12:22:52 +00:00
WinClient *client = findClient(ne.window);
if (client == 0)
return;
2003-05-01 13:19:36 +00:00
if (!ne.override_redirect && isVisible()) {
2002-12-01 13:42:15 +00:00
Fluxbox *fluxbox = Fluxbox::instance();
fluxbox->grab();
if (! validateClient())
return;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
setState(NormalState);
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
if (client->isTransient() || screen().doFocusNew())
2002-12-01 13:42:15 +00:00
setInputFocus();
else
setFocusFlag(false);
if (focused)
2003-05-15 11:17:29 +00:00
frame().setFocus(true);
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
iconic = false;
2002-12-01 13:42:15 +00:00
// Auto-group from tab?
if (!client->isTransient()) {
2003-05-13 14:05:00 +00:00
#ifdef DEBUG
2003-04-14 15:01:55 +00:00
cerr<<__FILE__<<"("<<__FUNCTION__<<") TODO check grouping here"<<endl;
2003-05-13 14:05:00 +00:00
#endif // DEBUG
2002-12-01 13:42:15 +00:00
}
fluxbox->ungrab();
}
2001-12-11 20:47:02 +00:00
}
/**
Unmaps frame window and client window if
2003-04-14 15:01:55 +00:00
event.window == m_client->window
Returns true if *this should die
else false
*/
void FluxboxWindow::unmapNotifyEvent(XUnmapEvent &ue) {
2003-04-14 15:01:55 +00:00
WinClient *client = findClient(ue.window);
if (client == 0)
return;
#ifdef DEBUG
2003-04-14 15:01:55 +00:00
cerr<<__FILE__<<"("<<__FUNCTION__<<"): 0x"<<hex<<client->window()<<dec<<endl;
2003-04-15 12:22:52 +00:00
cerr<<__FILE__<<"("<<__FUNCTION__<<"): title="<<client->title()<<endl;
#endif // DEBUG
2003-04-14 15:01:55 +00:00
restore(client, false);
2001-12-11 20:47:02 +00:00
}
/**
2003-04-14 15:01:55 +00:00
Checks if event is for m_client->window.
*/
void FluxboxWindow::destroyNotifyEvent(XDestroyWindowEvent &de) {
2003-04-14 15:01:55 +00:00
if (de.window == m_client->window()) {
#ifdef DEBUG
2002-12-01 13:42:15 +00:00
cerr<<__FILE__<<"("<<__LINE__<<"): DestroyNotifyEvent this="<<this<<endl;
#endif // DEBUG
2003-04-14 15:01:55 +00:00
if (numClients() == 1)
2003-05-15 11:17:29 +00:00
frame().hide();
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::propertyNotifyEvent(Atom atom) {
2002-12-01 13:42:15 +00:00
switch(atom) {
case XA_WM_CLASS:
case XA_WM_CLIENT_MACHINE:
case XA_WM_COMMAND:
break;
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
case XA_WM_TRANSIENT_FOR: {
// TODO: this property notify should be handled by winclient
// but for now we'll justhave to update all transient info
//bool was_transient = isTransient();
ClientList::iterator it = clientList().begin();
ClientList::iterator it_end = clientList().end();
for (; it != it_end; it++)
(*it)->updateTransientInfo();
2002-12-01 13:42:15 +00:00
reconfigure();
// TODO: this is broken whilst we don't know which client
2003-04-14 15:01:55 +00:00
// update our layer to be the same layer as our transient for
//if (isTransient() && isTransient() != was_transient)
2003-05-15 11:17:29 +00:00
// layerItem().setLayer(getTransientFor()->layerItem().getLayer());
2003-04-14 15:01:55 +00:00
} break;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
case XA_WM_HINTS:
getWMHints();
break;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
case XA_WM_ICON_NAME:
updateIconNameFromClient();
2002-12-01 13:42:15 +00:00
updateIcon();
break;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
case XA_WM_NAME:
updateTitleFromClient();
2002-01-04 21:21:43 +00:00
2002-12-01 13:42:15 +00:00
if (! iconic)
2003-05-10 16:53:09 +00:00
screen().getWorkspace(m_workspace_number)->update();
2002-12-01 13:42:15 +00:00
else
updateIcon();
2002-04-04 22:39:52 +00:00
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
break;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
case XA_WM_NORMAL_HINTS: {
getWMNormalHints();
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
if ((m_client->normal_hint_flags & PMinSize) &&
(m_client->normal_hint_flags & PMaxSize)) {
2003-02-22 18:28:32 +00:00
2003-04-14 15:01:55 +00:00
if (m_client->max_width != 0 && m_client->max_width <= m_client->min_width &&
m_client->max_height != 0 && m_client->max_height <= m_client->min_height) {
2002-12-01 13:42:15 +00:00
decorations.maximize = false;
decorations.handle = false;
functions.resize=false;
functions.maximize=false;
} else {
// TODO: is broken while handled by FbW, needs to be in WinClient
if (! winClient().isTransient()) {
2002-12-01 13:42:15 +00:00
decorations.maximize = true;
decorations.handle = true;
functions.maximize = true;
}
functions.resize = true;
}
2002-09-14 12:31:18 +00:00
}
2001-12-11 20:47:02 +00:00
// save old values
2003-05-15 11:17:29 +00:00
int x = frame().x(), y = frame().y();
unsigned int w = frame().width(), h = frame().height();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
upsize();
2001-12-11 20:47:02 +00:00
// reconfigure if the old values changed
2003-05-15 11:17:29 +00:00
if (x != frame().x() || y != frame().y() ||
w != frame().width() || h != frame().height()) {
moveResize(x, y, w, h);
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
break;
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
default:
if (atom == FbAtoms::instance()->getWMProtocolsAtom()) {
2002-12-01 13:42:15 +00:00
getWMProtocols();
//!!TODO check this area
// reset window actions
2003-05-10 16:53:09 +00:00
screen().setupWindowActions(*this);
2002-12-01 13:42:15 +00:00
}
break;
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::exposeEvent(XExposeEvent &ee) {
2003-05-15 11:17:29 +00:00
frame().exposeEvent(ee);
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) {
2003-04-15 12:22:52 +00:00
WinClient *client = findClient(cr.window);
if (client == 0)
return;
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
int cx = frame().x(), cy = frame().y();
unsigned int cw = frame().width(), ch = frame().height();
if (cr.value_mask & CWBorderWidth)
2003-04-15 12:22:52 +00:00
client->old_bw = cr.border_width;
2002-12-01 13:42:15 +00:00
if (cr.value_mask & CWX)
2003-02-19 14:53:38 +00:00
cx = cr.x;
2002-12-01 13:42:15 +00:00
if (cr.value_mask & CWY)
cy = cr.y;
2002-12-01 13:42:15 +00:00
if (cr.value_mask & CWWidth)
2003-02-19 14:53:38 +00:00
cw = cr.width;
if (cr.value_mask & CWHeight)
ch = cr.height;
// whether we should send ConfigureNotify to clients
bool send_notify = false;
// the request is for client window so we resize the frame to it first
if (frame().width() != cw || frame().height() != ch) {
frame().resizeForClient(cw, ch);
send_notify = true;
}
if (frame().x() != cx || frame().y() != cy) {
move(cx, cy);
// since we already send a notify in move we don't need to do that again
send_notify = false;
}
if (send_notify)
sendConfigureNotify();
if (cr.value_mask & CWStackMode) {
switch (cr.detail) {
case Above:
case TopIf:
default:
raise();
break;
case Below:
case BottomIf:
lower();
break;
2002-12-01 13:42:15 +00:00
}
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::buttonPressEvent(XButtonEvent &be) {
m_last_button_x = be.x_root;
m_last_button_y = be.y_root;
// check frame events first
2003-05-15 11:17:29 +00:00
frame().buttonPressEvent(be);
if (be.button == 1 || (be.button == 3 && be.state == Mod1Mask)) {
2003-05-10 16:53:09 +00:00
if ((! focused) && (! screen().isSloppyFocus())) { //check focus
2002-12-01 13:42:15 +00:00
setInputFocus();
}
2002-11-12 22:04:16 +00:00
2003-05-15 11:17:29 +00:00
if (frame().clientArea() == be.window) {
2003-05-10 16:53:09 +00:00
if (screen().clickRaises())
raise();
2003-02-17 22:42:52 +00:00
XAllowEvents(display, ReplayPointer, be.time);
} else {
2003-05-15 11:17:29 +00:00
m_button_grab_x = be.x_root - frame().x() - screen().rootTheme().borderWidth();
m_button_grab_y = be.y_root - frame().y() - screen().rootTheme().borderWidth();
2002-12-01 13:42:15 +00:00
}
2003-02-17 22:42:52 +00:00
if (m_windowmenu.isVisible())
2003-04-14 15:01:55 +00:00
m_windowmenu.hide();
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::buttonReleaseEvent(XButtonEvent &re) {
2003-04-14 15:01:55 +00:00
2002-12-01 13:42:15 +00:00
if (isMoving())
stopMoving();
else if (isResizing())
stopResizing();
2003-04-15 14:40:24 +00:00
else if (m_attaching_tab)
attachTo(re.x_root, re.y_root);
2003-05-15 11:17:29 +00:00
else if (re.window == frame().window()) {
if (re.button == 2 && re.state == Mod1Mask)
2002-12-01 13:42:15 +00:00
XUngrabPointer(display, CurrentTime);
2003-04-15 14:40:24 +00:00
else
2003-05-15 11:17:29 +00:00
frame().buttonReleaseEvent(re);
2003-04-14 15:01:55 +00:00
} else {
2003-05-15 11:17:29 +00:00
frame().buttonReleaseEvent(re);
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
if (isMoving() && me.window == parent()) {
2003-05-15 11:17:29 +00:00
me.window = frame().window().window();
2003-03-22 05:13:08 +00:00
}
2003-05-15 11:17:29 +00:00
bool inside_titlebar = (frame().titlebar() == me.window || frame().label() == me.window ||
frame().handle() == me.window || frame().window() == me.window);
if (Fluxbox::instance()->getIgnoreBorder()
&& !(me.state & Mod1Mask) // really should check for exact matches
&& !(isMoving() || isResizing())) {
2003-05-10 16:53:09 +00:00
int borderw = screen().rootTheme().borderWidth();
2003-05-15 11:17:29 +00:00
if (me.x_root < (frame().x() + borderw) ||
me.y_root < (frame().y() + borderw) ||
me.x_root > (frame().x() + (int)frame().width() + borderw) ||
me.y_root > (frame().y() + (int)frame().height() + borderw))
return;
}
2003-04-15 14:40:24 +00:00
WinClient *client = 0;
2003-04-14 15:01:55 +00:00
if (!inside_titlebar) {
// determine if we're in titlebar
Client2ButtonMap::iterator it = m_labelbuttons.begin();
Client2ButtonMap::iterator it_end = m_labelbuttons.end();
for (; it != it_end; ++it) {
if ((*it).second->window() == me.window) {
inside_titlebar = true;
2003-04-15 14:40:24 +00:00
client = (*it).first;
2003-04-14 15:01:55 +00:00
break;
}
}
}
if ((me.state & Button1Mask) && functions.move &&
2003-04-14 15:01:55 +00:00
inside_titlebar &&
!isResizing()) {
2002-12-01 13:42:15 +00:00
if (! isMoving()) {
startMoving(me.window);
2003-05-04 13:55:39 +00:00
} else {
2003-05-10 16:53:09 +00:00
int dx = me.x_root - m_button_grab_x,
dy = me.y_root - m_button_grab_y;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
dx -= screen().rootTheme().borderWidth();
dy -= screen().rootTheme().borderWidth();
2002-12-01 13:42:15 +00:00
// Warp to next or previous workspace?, must have moved sideways some
2003-05-10 16:53:09 +00:00
int moved_x = me.x_root - m_last_resize_x;
2002-12-01 13:42:15 +00:00
// save last event point
2003-05-10 16:53:09 +00:00
m_last_resize_x = me.x_root;
m_last_resize_y = me.y_root;
2003-04-14 15:01:55 +00:00
2003-05-10 16:53:09 +00:00
if (moved_x && screen().isWorkspaceWarping()) {
2003-05-15 12:00:46 +00:00
unsigned int cur_id = screen().currentWorkspaceID();
2003-03-22 05:13:08 +00:00
unsigned int new_id = cur_id;
2003-05-10 16:53:09 +00:00
const int warpPad = screen().getEdgeSnapThreshold();
2003-03-22 05:13:08 +00:00
// 1) if we're inside the border threshold
// 2) if we moved in the right direction
2003-05-15 12:00:46 +00:00
if (me.x_root >= int(screen().width()) - warpPad - 1 &&
2003-03-22 05:13:08 +00:00
moved_x > 0) {
2002-12-01 13:42:15 +00:00
//warp right
2003-05-10 16:53:09 +00:00
new_id = (cur_id + 1) % screen().getCount();
dx = - me.x_root; // move mouse back to x=0
} else if (me.x_root <= warpPad &&
2003-04-14 15:01:55 +00:00
moved_x < 0) {
2002-12-01 13:42:15 +00:00
//warp left
2003-05-10 16:53:09 +00:00
new_id = (cur_id + screen().getCount() - 1) % screen().getCount();
2003-05-15 12:00:46 +00:00
dx = screen().width() - me.x_root-1; // move mouse to screen width - 1
2002-12-01 13:42:15 +00:00
}
if (new_id != cur_id) {
XWarpPointer(display, None, None, 0, 0, 0, 0, dx, 0);
2003-04-14 15:01:55 +00:00
2003-05-10 16:53:09 +00:00
screen().changeWorkspaceID(new_id);
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
m_last_resize_x = me.x_root + dx;
2003-03-22 05:13:08 +00:00
// dx is the difference, so our new x is what it would have been
// without the warp, plus the difference.
2003-05-10 16:53:09 +00:00
dx += me.x_root - m_button_grab_x;
2002-12-01 13:42:15 +00:00
}
}
2003-04-20 02:47:15 +00:00
// dx = current left side, dy = current top
doSnapping(dx, dy);
2003-02-17 22:42:52 +00:00
2003-05-10 16:53:09 +00:00
if (! screen().doOpaqueMove()) {
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
2003-05-15 11:17:29 +00:00
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
parent().drawRectangle(screen().rootTheme().opGC(),
dx, dy,
2003-05-15 11:17:29 +00:00
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
2003-05-10 16:53:09 +00:00
m_last_move_x = dx;
m_last_move_y = dy;
2003-02-17 22:42:52 +00:00
} else {
2003-05-15 11:17:29 +00:00
moveResize(dx, dy, frame().width(), frame().height());
2003-02-17 22:42:52 +00:00
}
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if (screen().doShowWindowPos())
screen().showPosition(dx, dy);
2002-12-01 13:42:15 +00:00
} // end if moving
} else if (functions.resize &&
2003-05-15 11:17:29 +00:00
(((me.state & Button1Mask) && (me.window == frame().gripRight() ||
me.window == frame().gripLeft())) ||
me.window == frame().window())) {
2003-04-14 15:01:55 +00:00
2003-05-15 11:17:29 +00:00
bool left = (me.window == frame().gripLeft());
2002-12-01 13:42:15 +00:00
if (! resizing) {
startResizing(me.window, me.x, me.y, left);
2002-12-01 13:42:15 +00:00
} else if (resizing) {
// draw over old rect
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_resize_x, m_last_resize_y,
2003-05-15 11:17:29 +00:00
m_last_resize_w - 1 + 2 * frame().window().borderWidth(),
m_last_resize_h - 1 + 2 * frame().window().borderWidth());
2002-12-01 13:42:15 +00:00
// move rectangle
int gx = 0, gy = 0;
2002-12-01 13:42:15 +00:00
2003-05-15 11:17:29 +00:00
m_last_resize_h = frame().height() + (me.y - m_button_grab_y);
2003-05-10 16:53:09 +00:00
if (m_last_resize_h < 1)
m_last_resize_h = 1;
2002-12-01 13:42:15 +00:00
if (left) {
2003-05-10 16:53:09 +00:00
m_last_resize_x = me.x_root - m_button_grab_x;
2003-05-15 11:17:29 +00:00
if (m_last_resize_x > (signed) (frame().x() + frame().width()))
m_last_resize_x = m_last_resize_x + frame().width() - 1;
2002-12-01 13:42:15 +00:00
left_fixsize(&gx, &gy);
} else {
2003-05-15 11:17:29 +00:00
m_last_resize_w = frame().width() + (me.x - m_button_grab_x);
2003-05-10 16:53:09 +00:00
if (m_last_resize_w < 1) // clamp to 1
m_last_resize_w = 1;
2002-12-01 13:42:15 +00:00
right_fixsize(&gx, &gy);
}
// draw resize rectangle
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_resize_x, m_last_resize_y,
2003-05-15 11:17:29 +00:00
m_last_resize_w - 1 + 2 * frame().window().borderWidth(),
m_last_resize_h - 1 + 2 * frame().window().borderWidth());
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
if (screen().doShowWindowPos())
screen().showGeometry(gx, gy);
2003-04-15 14:40:24 +00:00
}
} else if ((me.state & Button2Mask) && inside_titlebar && client != 0) {
//
// drag'n'drop code for tabs
//
if (m_attaching_tab == 0) {
// start drag'n'drop for tab
m_attaching_tab = client;
XGrabPointer(display, me.window, False, Button2MotionMask |
ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
None, Fluxbox::instance()->getMoveCursor(), CurrentTime);
2003-05-10 16:53:09 +00:00
m_last_move_x = me.x_root - 1;
m_last_move_y = me.y_root - 1;
2003-04-15 14:40:24 +00:00
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
m_labelbuttons[client]->width(),
m_labelbuttons[client]->height());
2003-04-15 14:40:24 +00:00
} else {
// we already grabed and started to drag'n'drop tab
// so we update drag'n'drop-rectangle
int dx = me.x_root - 1, dy = me.y_root - 1;
2003-05-10 16:53:09 +00:00
dx -= screen().rootTheme().borderWidth();
dy -= screen().rootTheme().borderWidth();
2003-04-15 14:40:24 +00:00
2003-05-10 16:53:09 +00:00
if (screen().getEdgeSnapThreshold()) {
2003-05-15 12:00:46 +00:00
int drx = screen().width() - (dx + 1);
2003-04-15 14:40:24 +00:00
2003-05-10 16:53:09 +00:00
if (dx > 0 && dx < drx && dx < screen().getEdgeSnapThreshold())
2003-04-15 14:40:24 +00:00
dx = 0;
2003-05-10 16:53:09 +00:00
else if (drx > 0 && drx < screen().getEdgeSnapThreshold())
2003-05-15 12:00:46 +00:00
dx = screen().width() - 1;
2003-04-15 14:40:24 +00:00
int dty, dby;
dty = dy;
dby = -dy - 1;
2003-05-10 16:53:09 +00:00
if (dy > 0 && dty < screen().getEdgeSnapThreshold())
2003-04-15 14:40:24 +00:00
dy = 0;
2003-05-10 16:53:09 +00:00
else if (dby > 0 && dby < screen().getEdgeSnapThreshold())
2003-04-15 14:40:24 +00:00
dy = - 1;
}
//erase rectangle
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
m_labelbuttons[client]->width(),
m_labelbuttons[client]->height());
2003-04-15 14:40:24 +00:00
2003-05-10 16:53:09 +00:00
// redraw rectangle at new pos
m_last_move_x = dx;
m_last_move_y = dy;
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
m_labelbuttons[client]->width(),
m_labelbuttons[client]->height());
2003-04-15 14:40:24 +00:00
2002-12-01 13:42:15 +00:00
}
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::enterNotifyEvent(XCrossingEvent &ev) {
// ignore grab activates, or if we're not visible
if (ev.mode == NotifyGrab ||
!isVisible()) {
return;
}
2003-05-08 15:06:59 +00:00
WinClient *client = 0;
// don't waste our time scanning if we aren't real sloppy focus
2003-05-10 16:53:09 +00:00
if (screen().isSloppyFocus()) {
2003-05-08 15:06:59 +00:00
// determine if we're in a label button (tab)
Client2ButtonMap::iterator it = m_labelbuttons.begin();
Client2ButtonMap::iterator it_end = m_labelbuttons.end();
for (; it != it_end; ++it) {
if ((*it).second->window() == ev.window) {
client = (*it).first;
break;
}
}
}
2003-02-22 18:28:32 +00:00
if (ev.window == frame().window() ||
2003-05-08 15:06:59 +00:00
ev.window == m_client->window() ||
client) {
2003-05-10 16:53:09 +00:00
if ((screen().isSloppyFocus() || screen().isSemiSloppyFocus())
2003-05-08 15:06:59 +00:00
&& !isFocused() ||
// or, we are focused, but it isn't the one we want
2003-05-10 16:53:09 +00:00
client && screen().isSloppyFocus() && (m_client != client)) {
// check that there aren't any subsequent leave notify events in the
// X event queue
XEvent dummy;
scanargs sa;
sa.w = ev.window;
sa.enter = sa.leave = False;
XCheckIfEvent(display, &dummy, queueScanner, (char *) &sa);
2003-05-08 15:06:59 +00:00
// if client is set, use setCurrent client, otherwise just setInputFocus
if ((!sa.leave || sa.inferior) &&
((client && setCurrentClient(*client, true)) || setInputFocus()))
installColormap(True);
}
}
}
void FluxboxWindow::leaveNotifyEvent(XCrossingEvent &ev) {
2003-02-22 18:28:32 +00:00
if (ev.window == frame().window())
installColormap(false);
}
// TODO: functions should not be affected by decoration
void FluxboxWindow::setDecoration(Decoration decoration) {
2002-12-01 13:42:15 +00:00
switch (decoration) {
case DECOR_NONE:
decorations.titlebar = decorations.border = decorations.handle =
decorations.iconify = decorations.maximize =
decorations.tab = false; //tab is also a decor
decorations.menu = true; // menu is present
// functions.iconify = functions.maximize = true;
// functions.move = true; // We need to move even without decor
// functions.resize = true; // We need to resize even without decor
break;
2002-12-01 13:42:15 +00:00
default:
case DECOR_NORMAL:
decorations.titlebar = decorations.border = decorations.handle =
decorations.iconify = decorations.maximize =
decorations.menu = true;
functions.resize = functions.move = functions.iconify =
functions.maximize = true;
break;
2002-12-01 13:42:15 +00:00
case DECOR_TINY:
decorations.titlebar = decorations.iconify = decorations.menu =
functions.move = functions.iconify = true;
decorations.border = decorations.handle = decorations.maximize =
functions.resize = functions.maximize = false;
break;
2002-12-01 13:42:15 +00:00
case DECOR_TOOL:
decorations.titlebar = decorations.menu = functions.move = true;
decorations.iconify = decorations.border = decorations.handle =
decorations.maximize = functions.resize = functions.maximize =
functions.iconify = false;
break;
2002-12-01 13:42:15 +00:00
}
2003-04-28 13:38:23 +00:00
applyDecorations();
// is this reconfigure necessary???
2002-12-01 13:42:15 +00:00
reconfigure();
}
2003-04-28 13:38:23 +00:00
// commit current decoration values to actual displayed things
void FluxboxWindow::applyDecorations() {
// we rely on frame not doing anything if it is already shown/hidden
if (decorations.titlebar)
2003-05-15 11:17:29 +00:00
frame().showTitlebar();
2003-04-28 13:38:23 +00:00
else
2003-05-15 11:17:29 +00:00
frame().hideTitlebar();
2003-04-28 13:38:23 +00:00
if (decorations.handle)
2003-05-15 11:17:29 +00:00
frame().showHandle();
2003-04-28 13:38:23 +00:00
else
2003-05-15 11:17:29 +00:00
frame().hideHandle();
2003-04-28 13:38:23 +00:00
// is reconfigure needed here?
}
void FluxboxWindow::toggleDecoration() {
2002-12-01 13:42:15 +00:00
//don't toggle decor if the window is shaded
if (isShaded())
return;
if (decorations.enabled) { //remove decorations
setDecoration(DECOR_NONE);
decorations.enabled = false;
} else { //revert back to old decoration
2003-05-10 16:53:09 +00:00
if (m_old_decoration == DECOR_NONE) { // make sure something happens
setDecoration(DECOR_NORMAL);
} else {
2003-05-10 16:53:09 +00:00
setDecoration(m_old_decoration);
}
2002-12-01 13:42:15 +00:00
decorations.enabled = true;
}
}
2002-05-21 21:25:10 +00:00
2003-05-15 11:17:29 +00:00
unsigned int FluxboxWindow::decorationMask() const {
unsigned int ret = 0;
if (decorations.titlebar)
ret |= DECORM_TITLEBAR;
if (decorations.handle)
ret |= DECORM_HANDLE;
if (decorations.border)
ret |= DECORM_BORDER;
if (decorations.iconify)
ret |= DECORM_ICONIFY;
if (decorations.maximize)
ret |= DECORM_MAXIMIZE;
if (decorations.close)
ret |= DECORM_CLOSE;
if (decorations.menu)
ret |= DECORM_MENU;
if (decorations.sticky)
ret |= DECORM_STICKY;
if (decorations.shade)
ret |= DECORM_SHADE;
if (decorations.tab)
ret |= DECORM_TAB;
if (decorations.enabled)
ret |= DECORM_ENABLED;
return ret;
}
void FluxboxWindow::setDecorationMask(unsigned int mask) {
decorations.titlebar = mask & DECORM_TITLEBAR;
decorations.handle = mask & DECORM_HANDLE;
decorations.border = mask & DECORM_BORDER;
decorations.iconify = mask & DECORM_ICONIFY;
decorations.maximize = mask & DECORM_MAXIMIZE;
decorations.close = mask & DECORM_CLOSE;
decorations.menu = mask & DECORM_MENU;
decorations.sticky = mask & DECORM_STICKY;
decorations.shade = mask & DECORM_SHADE;
decorations.tab = mask & DECORM_TAB;
decorations.enabled = mask & DECORM_ENABLED;
2003-04-28 13:38:23 +00:00
applyDecorations();
}
bool FluxboxWindow::validateClient() {
2002-12-01 13:42:15 +00:00
XSync(display, false);
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
XEvent e;
2003-04-14 15:01:55 +00:00
if (XCheckTypedWindowEvent(display, m_client->window(), DestroyNotify, &e) ||
XCheckTypedWindowEvent(display, m_client->window(), UnmapNotify, &e)) {
2002-12-01 13:42:15 +00:00
XPutBackEvent(display, &e);
Fluxbox::instance()->ungrab();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
return false;
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
return true;
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::startMoving(Window win) {
2002-12-01 13:42:15 +00:00
moving = true;
Fluxbox *fluxbox = Fluxbox::instance();
2003-03-22 05:13:08 +00:00
// grabbing (and masking) on the root window allows us to
// freely map and unmap the window we're moving.
XGrabPointer(display, screen().rootWindow().window(), False, Button1MotionMask |
2002-12-01 13:42:15 +00:00
ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
screen().rootWindow().window(), fluxbox->getMoveCursor(), CurrentTime);
if (m_windowmenu.isVisible())
m_windowmenu.hide();
fluxbox->maskWindowEvents(screen().rootWindow().window(), this);
2003-04-14 15:01:55 +00:00
2003-05-10 16:53:09 +00:00
m_last_move_x = frame().x();
m_last_move_y = frame().y();
if (! screen().doOpaqueMove()) {
2003-03-22 05:13:08 +00:00
fluxbox->grab();
parent().drawRectangle(screen().rootTheme().opGC(),
frame().x(), frame().y(),
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
2003-05-10 16:53:09 +00:00
screen().showPosition(frame().x(), frame().y());
2003-02-17 22:42:52 +00:00
}
}
void FluxboxWindow::stopMoving() {
2002-12-01 13:42:15 +00:00
moving = false;
Fluxbox *fluxbox = Fluxbox::instance();
2003-02-17 22:42:52 +00:00
fluxbox->maskWindowEvents(0, 0);
2003-02-17 22:42:52 +00:00
2003-05-10 16:53:09 +00:00
if (! screen().doOpaqueMove()) {
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
2003-05-15 11:17:29 +00:00
moveResize(m_last_move_x, m_last_move_y, frame().width(), frame().height());
2003-05-15 12:00:46 +00:00
if (m_workspace_number != screen().currentWorkspaceID()) {
screen().reassociateWindow(this, screen().currentWorkspaceID(), true);
2003-05-15 11:17:29 +00:00
frame().show();
2003-03-22 05:13:08 +00:00
}
fluxbox->ungrab();
2003-02-17 22:42:52 +00:00
} else
2003-05-15 11:17:29 +00:00
moveResize(frame().x(), frame().y(), frame().width(), frame().height());
2003-05-10 16:53:09 +00:00
screen().hideGeometry();
2002-12-01 13:42:15 +00:00
XUngrabPointer(display, CurrentTime);
2002-12-01 13:42:15 +00:00
XSync(display, False); //make sure the redraw is made before we continue
}
void FluxboxWindow::pauseMoving() {
2003-05-10 16:53:09 +00:00
if (screen().doOpaqueMove()) {
2003-03-22 05:13:08 +00:00
return;
}
2002-12-01 13:42:15 +00:00
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
2003-05-15 11:17:29 +00:00
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
2003-03-22 05:13:08 +00:00
}
void FluxboxWindow::resumeMoving() {
2003-05-10 16:53:09 +00:00
if (screen().doOpaqueMove()) {
2003-03-22 05:13:08 +00:00
return;
}
2003-05-15 12:00:46 +00:00
if (m_workspace_number == screen().currentWorkspaceID()) {
2003-05-15 11:17:29 +00:00
frame().show();
2003-03-22 05:13:08 +00:00
}
XSync(display,false);
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
2003-05-15 11:17:29 +00:00
frame().width() + 2*frame().window().borderWidth()-1,
frame().height() + 2*frame().window().borderWidth()-1);
2003-04-20 02:47:15 +00:00
}
/**
* Helper function that snaps a window to another window
* We snap if we're closer than the x/ylimits.
*/
inline void snapToWindow(int &xlimit, int &ylimit,
int left, int right, int top, int bottom,
int oleft, int oright, int otop, int obottom) {
// Only snap if we're adjacent to the edge we're looking at
// for left + right, need to be in the right y range
if (top <= obottom && bottom >= otop) {
// left
if (abs(left-oleft) < abs(xlimit)) xlimit = -(left-oleft);
if (abs(right-oleft) < abs(xlimit)) xlimit = -(right-oleft);
// right
if (abs(left-oright) < abs(xlimit)) xlimit = -(left-oright);
if (abs(right-oright) < abs(xlimit)) xlimit = -(right-oright);
}
// for top + bottom, need to be in the right x range
if (left <= oright && right >= oleft) {
// top
if (abs(top-otop) < abs(ylimit)) ylimit = -(top-otop);
if (abs(bottom-otop) < abs(ylimit)) ylimit = -(bottom-otop);
// bottom
if (abs(top-obottom) < abs(ylimit)) ylimit = -(top-obottom);
if (abs(bottom-obottom) < abs(ylimit)) ylimit = -(bottom-obottom);
}
}
/*
* Do Whatever snapping magic is necessary, and return using the orig_left
* and orig_top variables to indicate the new x,y position
2003-04-20 02:47:15 +00:00
*/
void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
/*
* Snap to screen/head edges
2003-04-20 02:47:15 +00:00
* Snap to windows
* Snap to toolbar
* Snap to slit
*/
2003-05-10 16:53:09 +00:00
if (screen().getEdgeSnapThreshold() == 0) return;
2003-04-20 02:47:15 +00:00
// Keep track of our best offsets so far
// We need to find things less than or equal to the threshold
2003-05-10 16:53:09 +00:00
int dx = screen().getEdgeSnapThreshold() + 1;
int dy = screen().getEdgeSnapThreshold() + 1;
2003-04-20 02:47:15 +00:00
// we only care about the left/top etc that includes borders
2003-05-15 11:17:29 +00:00
int borderW = frame().window().borderWidth();
2003-04-20 02:47:15 +00:00
int top = orig_top; // orig include the borders
int left = orig_left;
2003-05-11 13:36:12 +00:00
int right = orig_left + width() + 2*borderW;
int bottom = orig_top + height() + 2*borderW;
2003-04-20 02:47:15 +00:00
/////////////////////////////////////
// begin by checking the screen (or Xinerama head) edges
if (screen().hasXinerama()) {
// head "0" == whole screen width + height, which we skip since the
// sum of all the heads covers those edges
for (int h = 1; h <= screen().numHeads(); h++) {
snapToWindow(dx, dy, left, right, top, bottom,
screen().maxLeft(h),
screen().maxRight(h),
screen().maxTop(h),
screen().maxBottom(h));
}
} else
snapToWindow(dx, dy, left, right, top, bottom, 0, screen().width(), 0, screen().height());
2003-04-20 02:47:15 +00:00
/////////////////////////////////////
// now check window edges
Workspace::Windows &wins =
2003-05-15 12:00:46 +00:00
screen().currentWorkspace()->windowList();
2003-04-20 02:47:15 +00:00
Workspace::Windows::iterator it = wins.begin();
Workspace::Windows::iterator it_end = wins.end();
for (; it != it_end; it++) {
if ((*it) == this) continue; // skip myself
snapToWindow(dx, dy, left, right, top, bottom,
2003-05-15 11:17:29 +00:00
(*it)->x(),
(*it)->x() + (*it)->width() + 2*borderW,
(*it)->y(),
(*it)->y() + (*it)->height() + 2*borderW);
2003-04-20 02:47:15 +00:00
}
// commit
2003-05-10 16:53:09 +00:00
if (dx <= screen().getEdgeSnapThreshold())
2003-04-20 02:47:15 +00:00
orig_left += dx;
2003-05-10 16:53:09 +00:00
if (dy <= screen().getEdgeSnapThreshold())
2003-04-20 02:47:15 +00:00
orig_top += dy;
2002-12-01 13:42:15 +00:00
}
void FluxboxWindow::startResizing(Window win, int x, int y, bool left) {
2002-12-01 13:42:15 +00:00
resizing = true;
Fluxbox *fluxbox = Fluxbox::instance();
XGrabPointer(display, win, false, ButtonMotionMask | ButtonReleaseMask,
2002-12-01 13:42:15 +00:00
GrabModeAsync, GrabModeAsync, None,
(left ? fluxbox->getLowerLeftAngleCursor() : fluxbox->getLowerRightAngleCursor()),
2002-12-01 13:42:15 +00:00
CurrentTime);
int gx = 0, gy = 0;
2003-05-10 16:53:09 +00:00
m_button_grab_x = x;
m_button_grab_y = y;
2003-05-15 11:17:29 +00:00
m_last_resize_x = frame().x();
m_last_resize_y = frame().y();
m_last_resize_w = frame().width();
m_last_resize_h = frame().height();
2002-12-01 13:42:15 +00:00
if (left)
left_fixsize(&gx, &gy);
else
right_fixsize(&gx, &gy);
2003-05-10 16:53:09 +00:00
if (screen().doShowWindowPos())
screen().showGeometry(gx, gy);
2002-12-01 13:42:15 +00:00
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_resize_x, m_last_resize_y,
2003-05-15 11:17:29 +00:00
m_last_resize_w - 1 + 2 * frame().window().borderWidth(),
m_last_resize_h - 1 + 2 * frame().window().borderWidth());
}
void FluxboxWindow::stopResizing(Window win) {
2002-12-01 13:42:15 +00:00
resizing = false;
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_resize_x, m_last_resize_y,
2003-05-15 11:17:29 +00:00
m_last_resize_w - 1 + 2 * frame().window().borderWidth(),
m_last_resize_h - 1 + 2 * frame().window().borderWidth());
2003-05-10 16:53:09 +00:00
screen().hideGeometry();
2003-05-15 11:17:29 +00:00
if (win && win == frame().gripLeft())
2002-12-01 13:42:15 +00:00
left_fixsize();
else
right_fixsize();
2003-05-10 16:53:09 +00:00
moveResize(m_last_resize_x, m_last_resize_y,
m_last_resize_w, m_last_resize_h);
2002-12-01 13:42:15 +00:00
XUngrabPointer(display, CurrentTime);
}
2001-12-11 20:47:02 +00:00
2003-04-15 14:40:24 +00:00
void FluxboxWindow::attachTo(int x, int y) {
if (m_attaching_tab == 0)
return;
XUngrabPointer(display, CurrentTime);
parent().drawRectangle(screen().rootTheme().opGC(),
m_last_move_x, m_last_move_y,
m_labelbuttons[m_attaching_tab]->width(),
m_labelbuttons[m_attaching_tab]->height());
2003-04-15 14:40:24 +00:00
int dest_x = 0, dest_y = 0;
Window child = 0;
if (XTranslateCoordinates(display, parent().window(),
parent().window(),
2003-04-15 14:40:24 +00:00
x, y, &dest_x, &dest_y, &child)) {
// search for a fluxboxwindow
FluxboxWindow *attach_to_win = Fluxbox::instance()->searchWindow(child);
if (attach_to_win != this &&
attach_to_win != 0) {
attach_to_win->attachClient(*m_attaching_tab);
} else if (attach_to_win != this) { // disconnect client if we didn't drop on a window
detachClient(*m_attaching_tab);
}
}
m_attaching_tab = 0;
}
2002-04-04 22:39:52 +00:00
//finds and redraw the icon label
void FluxboxWindow::updateIcon() {
2003-05-15 12:00:46 +00:00
//!! TODO we shouldn't know about the toolbar in fluxboxwindow!
if (screen().toolbar()) {
2002-12-01 13:42:15 +00:00
const IconBar *iconbar = 0;
const IconBarObj *icon = 0;
2003-05-15 12:00:46 +00:00
if ((iconbar = screen().toolbar()->iconBar()) != 0) {
2002-12-01 13:42:15 +00:00
if ((icon = iconbar->findIcon(this)) != 0)
iconbar->draw(icon, icon->width());
}
}
2002-04-04 22:39:52 +00:00
}
2003-04-14 15:01:55 +00:00
void FluxboxWindow::restore(WinClient *client, bool remap) {
if (client->m_win != this)
return;
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
XChangeSaveSet(display, client->window(), SetModeDelete);
client->setEventMask(NoEventMask);
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
//!! TODO
//restoreGravity();
2003-04-14 15:01:55 +00:00
client->hide();
2001-12-11 20:47:02 +00:00
// restore old border width
2003-04-14 15:01:55 +00:00
client->setBorderWidth(client->old_bw);
2003-04-14 15:01:55 +00:00
XEvent not_used;
if (! XCheckTypedWindowEvent(display, client->window(), ReparentNotify,
&not_used)) {
#ifdef DEBUG
2003-04-14 15:01:55 +00:00
cerr<<"FluxboxWindow::restore: reparent 0x"<<hex<<client->window()<<dec<<" to root"<<endl;
#endif // DEBUG
2003-04-14 15:01:55 +00:00
// reparent to root window
2003-05-15 11:17:29 +00:00
client->reparent(screen().rootWindow().window(), frame().x(), frame().y());
2002-12-01 13:42:15 +00:00
}
2002-12-01 13:42:15 +00:00
if (remap)
2003-04-14 15:01:55 +00:00
client->show();
delete client;
2003-04-15 12:22:52 +00:00
#ifdef DEBUG
cerr<<__FILE__<<"("<<__FUNCTION__<<"): numClients() = "<<numClients()<<endl;
#endif // DEBUG
if (numClients() == 0) {
2003-05-15 11:17:29 +00:00
frame().hide();
2003-04-15 12:22:52 +00:00
}
2001-12-11 20:47:02 +00:00
}
2003-04-14 15:01:55 +00:00
void FluxboxWindow::restore(bool remap) {
if (numClients() == 0)
return;
while (!clientList().empty()) {
restore(clientList().back(), remap);
}
}
2001-12-11 20:47:02 +00:00
void FluxboxWindow::timeout() {
raise();
2001-12-11 20:47:02 +00:00
}
2003-05-15 11:17:29 +00:00
bool FluxboxWindow::isVisible() const {
return frame().isVisible();
}
FbTk::FbWindow &FluxboxWindow::fbWindow() {
return frame().window();
}
const FbTk::FbWindow &FluxboxWindow::fbWindow() const {
return frame().window();
}
int FluxboxWindow::x() const {
return frame().x();
}
int FluxboxWindow::y() const {
return frame().y();
}
unsigned int FluxboxWindow::width() const {
return frame().width();
}
unsigned int FluxboxWindow::height() const {
return frame().height();
}
unsigned int FluxboxWindow::titlebarHeight() const {
return frame().titlebarHeight();
2003-05-15 11:17:29 +00:00
}
Window FluxboxWindow::clientWindow() const {
2003-04-14 15:01:55 +00:00
if (m_client == 0)
return 0;
return m_client->window();
}
2003-05-15 11:17:29 +00:00
const std::string &FluxboxWindow::title() const {
2003-04-14 15:01:55 +00:00
static string empty_string("");
if (m_client == 0)
return empty_string;
return m_client->title();
}
2003-05-15 11:17:29 +00:00
const std::string &FluxboxWindow::iconTitle() const {
2003-04-14 15:01:55 +00:00
static string empty_string("");
if (m_client == 0)
return empty_string;
return m_client->iconTitle();
}
int FluxboxWindow::initialState() const { return m_client->initial_state; }
2001-12-11 20:47:02 +00:00
2003-05-10 14:27:57 +00:00
void FluxboxWindow::changeBlackboxHints(const BlackboxHints &net) {
if ((net.flags & ATTRIB_SHADED) &&
2003-05-10 16:53:09 +00:00
((m_blackbox_attrib.attrib & ATTRIB_SHADED) !=
2003-05-10 14:27:57 +00:00
(net.attrib & ATTRIB_SHADED)))
2002-12-01 13:42:15 +00:00
shade();
2001-12-11 20:47:02 +00:00
2003-05-10 14:27:57 +00:00
if ((net.flags & (ATTRIB_MAXVERT | ATTRIB_MAXHORIZ)) &&
2003-05-10 16:53:09 +00:00
((m_blackbox_attrib.attrib & (ATTRIB_MAXVERT | ATTRIB_MAXHORIZ)) !=
2003-05-10 14:27:57 +00:00
(net.attrib & (ATTRIB_MAXVERT | ATTRIB_MAXHORIZ)))) {
2002-12-01 13:42:15 +00:00
if (maximized) {
maximize();
2002-12-01 13:42:15 +00:00
} else {
2003-05-10 14:27:57 +00:00
if ((net.flags & ATTRIB_MAXHORIZ) && (net.flags & ATTRIB_MAXVERT))
maximize();
2003-05-10 14:27:57 +00:00
else if (net.flags & ATTRIB_MAXVERT)
maximizeVertical();
2003-05-10 14:27:57 +00:00
else if (net.flags & ATTRIB_MAXHORIZ)
maximizeHorizontal();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
}
}
2003-04-14 15:01:55 +00:00
2003-05-10 14:27:57 +00:00
if ((net.flags & ATTRIB_OMNIPRESENT) &&
2003-05-10 16:53:09 +00:00
((m_blackbox_attrib.attrib & ATTRIB_OMNIPRESENT) !=
2003-05-10 14:27:57 +00:00
(net.attrib & ATTRIB_OMNIPRESENT)))
2002-12-01 13:42:15 +00:00
stick();
2001-12-11 20:47:02 +00:00
2003-05-10 14:27:57 +00:00
if ((net.flags & ATTRIB_WORKSPACE) &&
2003-05-10 16:53:09 +00:00
(m_workspace_number != net.workspace)) {
2001-12-11 20:47:02 +00:00
2003-05-10 16:53:09 +00:00
screen().reassociateWindow(this, net.workspace, true);
2002-12-01 13:42:15 +00:00
2003-05-15 12:00:46 +00:00
if (screen().currentWorkspaceID() != net.workspace)
2002-12-01 13:42:15 +00:00
withdraw();
else
deiconify();
}
2003-05-10 14:27:57 +00:00
if (net.flags & ATTRIB_STACK) {
if ((unsigned int) m_layernum != net.stack) {
2003-02-09 14:11:14 +00:00
moveToLayer(net.stack);
}
}
2003-05-10 14:27:57 +00:00
if (net.flags & ATTRIB_DECORATION) {
2003-05-10 16:53:09 +00:00
m_old_decoration = static_cast<Decoration>(net.decoration);
setDecoration(m_old_decoration);
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::upsize() {
2003-05-15 11:17:29 +00:00
frame().setBevel(screen().rootTheme().bevelWidth());
frame().handle().resize(frame().handle().width(),
2003-05-10 16:53:09 +00:00
screen().rootTheme().handleWidth());
2003-05-15 11:17:29 +00:00
frame().gripLeft().resize(frame().buttonHeight(),
2003-05-10 16:53:09 +00:00
screen().rootTheme().handleWidth());
2003-05-15 11:17:29 +00:00
frame().gripRight().resize(frame().gripLeft().width(),
frame().gripLeft().height());
2001-12-11 20:47:02 +00:00
}
///TODO
void FluxboxWindow::downsize() {
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::right_fixsize(int *gx, int *gy) {
2002-12-01 13:42:15 +00:00
// calculate the size of the client window and conform it to the
// size specified by the size hints of the client window...
2003-05-10 16:53:09 +00:00
int dx = m_last_resize_w - m_client->base_width;
2003-04-14 15:01:55 +00:00
int titlebar_height = (decorations.titlebar ?
frame().titlebar().height() +
frame().titlebar().borderWidth() : 0);
int handle_height = (decorations.handle ?
frame().handle().height() +
frame().handle().borderWidth() : 0);
2003-05-10 16:53:09 +00:00
int dy = m_last_resize_h - m_client->base_height - titlebar_height - handle_height;
2003-04-14 15:01:55 +00:00
if (dx < (signed) m_client->min_width)
dx = m_client->min_width;
if (dy < (signed) m_client->min_height)
dy = m_client->min_height;
if (m_client->max_width > 0 && (unsigned) dx > m_client->max_width)
dx = m_client->max_width;
if (m_client->max_height > 0 && (unsigned) dy > m_client->max_height)
dy = m_client->max_height;
2001-12-11 20:47:02 +00:00
// make it snap
2003-02-22 18:28:32 +00:00
2003-04-14 15:01:55 +00:00
if (m_client->width_inc == 0)
m_client->width_inc = 1;
if (m_client->height_inc == 0)
m_client->height_inc = 1;
2003-02-22 18:28:32 +00:00
2003-04-14 15:01:55 +00:00
dx /= m_client->width_inc;
dy /= m_client->height_inc;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
if (gx) *gx = dx;
if (gy) *gy = dy;
2001-12-11 20:47:02 +00:00
2003-04-14 15:01:55 +00:00
dx = (dx * m_client->width_inc) + m_client->base_width;
dy = (dy * m_client->height_inc) + m_client->base_height +
titlebar_height + handle_height;
2003-05-10 16:53:09 +00:00
m_last_resize_w = dx;
m_last_resize_h = dy;
2001-12-11 20:47:02 +00:00
}
2003-02-22 18:28:32 +00:00
void FluxboxWindow::left_fixsize(int *gx, int *gy) {
2003-04-14 15:01:55 +00:00
int titlebar_height = (decorations.titlebar ?
frame().titlebar().height() +
frame().titlebar().borderWidth() : 0);
int handle_height = (decorations.handle ?
frame().handle().height() +
frame().handle().borderWidth() : 0);
2003-02-22 18:28:32 +00:00
int decoration_height = titlebar_height + handle_height;
// dx is new width = current width + difference between new and old x values
2003-05-15 11:17:29 +00:00
int dx = frame().width() + frame().x() - m_last_resize_x;
// dy = new height (w/o decorations), similarly
2003-05-10 16:53:09 +00:00
int dy = m_last_resize_h - m_client->base_height - decoration_height;
// check minimum size
2003-04-14 15:01:55 +00:00
if (dx < static_cast<signed int>(m_client->min_width))
dx = m_client->min_width;
if (dy < static_cast<signed int>(m_client->min_height))
dy = m_client->min_height;
// check maximum size
2003-04-14 15:01:55 +00:00
if (m_client->max_width > 0 && dx > static_cast<signed int>(m_client->max_width))
dx = m_client->max_width;
if (m_client->max_height > 0 && dy > static_cast<signed int>(m_client->max_height))
dy = m_client->max_height;
2002-12-01 13:42:15 +00:00
// make sure we have valid increment
2003-04-14 15:01:55 +00:00
if (m_client->width_inc == 0)
m_client->width_inc = 1;
if (m_client->height_inc == 0)
m_client->height_inc = 1;
2002-12-01 13:42:15 +00:00
// set snapping
2003-04-14 15:01:55 +00:00
dx /= m_client->width_inc;
dy /= m_client->height_inc;
2002-12-01 13:42:15 +00:00
// set return values
if (gx != 0)
*gx = dx;
if (gy != 0)
*gy = dy;
2002-12-01 13:42:15 +00:00
// snapping
2003-04-14 15:01:55 +00:00
dx = dx * m_client->width_inc + m_client->base_width;
dy = dy * m_client->height_inc + m_client->base_height + decoration_height;
2002-12-01 13:42:15 +00:00
// update last resize
2003-05-10 16:53:09 +00:00
m_last_resize_w = dx;
m_last_resize_h = dy;
2003-05-15 11:17:29 +00:00
m_last_resize_x = frame().x() + frame().width() - m_last_resize_w;
2001-12-11 20:47:02 +00:00
}
void FluxboxWindow::resizeClient(WinClient &client,
unsigned int height, unsigned int width) {
2003-05-15 11:17:29 +00:00
client.resize(frame().clientArea().width(),
frame().clientArea().height());
client.updateRect(frame().x() + frame().clientArea().x(),
frame().y() + frame().clientArea().y(),
frame().clientArea().width(),
frame().clientArea().height());
}
void FluxboxWindow::sendConfigureNotify() {
ClientList::iterator client_it = m_clientlist.begin();
ClientList::iterator client_it_end = m_clientlist.end();
for (; client_it != client_it_end; ++client_it) {
WinClient &client = *(*client_it);
/*
Send event telling where the root position
of the client window is. (ie frame pos + client pos inside the frame = send pos)
*/
//!!
2003-05-15 11:17:29 +00:00
client.x = frame().x();
client.y = frame().y();
resizeClient(client,
2003-05-15 11:17:29 +00:00
frame().clientArea().width(),
frame().clientArea().height());
XEvent event;
event.type = ConfigureNotify;
event.xconfigure.display = display;
event.xconfigure.event = client.window();
event.xconfigure.window = client.window();
2003-05-15 11:17:29 +00:00
event.xconfigure.x = frame().x() + frame().clientArea().x();
event.xconfigure.y = frame().y() + frame().clientArea().y();
event.xconfigure.width = client.width();
event.xconfigure.height = client.height();
event.xconfigure.border_width = client.old_bw;
2003-05-15 11:17:29 +00:00
event.xconfigure.above = frame().window().window();
event.xconfigure.override_redirect = false;
2003-05-10 16:53:09 +00:00
screen().updateNetizenConfigNotify(&event);
} // end for
}