indentation and minor fbtk updates

This commit is contained in:
fluxgen 2002-12-05 00:07:39 +00:00
parent d0f0e2d438
commit 248639a7aa
3 changed files with 298 additions and 352 deletions

View file

@ -19,12 +19,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbRun.cc,v 1.8 2002/11/27 21:56:56 fluxgen Exp $
// $Id: FbRun.cc,v 1.9 2002/12/05 00:07:39 fluxgen Exp $
#include "FbRun.hh"
#include "App.hh"
#include "EventManager.hh"
#include "Color.hh"
#include <X11/Xlib.h>
#include <X11/keysym.h>
@ -37,20 +38,23 @@
using namespace std;
FbRun::FbRun(int x, int y, size_t width):
m_font("fixed"),
m_win(None),
m_display(FbTk::App::instance()->display()),
m_bevel(4),
m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
m_end(false),
m_current_history_item(0) {
createWindow(x, y, width + m_bevel, m_font.height());
m_font("fixed"),
m_win((int)0, x, y, //screen num and position
width + m_bevel, m_font.height(), // size
KeyPressMask|ExposureMask), // eventmask
m_display(FbTk::App::instance()->display()),
m_bevel(4),
m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
m_end(false),
m_current_history_item(0) {
// setting nomaximize in local resize
resize(width, m_font.height());
FbTk::EventManager::instance()->registerEventHandler(*this, m_win.window());
}
FbRun::~FbRun() {
hide();
FbTk::EventManager::instance()->unregisterEventHandler(m_win);
XDestroyWindow(m_display, m_win);
FbTk::EventManager::instance()->unregisterEventHandler(m_win.window());
}
void FbRun::run(const std::string &command) {
@ -58,7 +62,7 @@ void FbRun::run(const std::string &command) {
if (!fork()) {
setsid();
execl("/bin/sh", "/bin/sh", "-c", command.c_str(), 0);
exit(0); //exit fork
exit(0); //exit child
}
hide(); // hide gui
@ -106,17 +110,17 @@ bool FbRun::loadFont(const string &fontname) {
return false;
// resize to fit new font height
resize(m_width, m_font.height() + m_bevel);
resize(m_win.width(), m_font.height() + m_bevel);
return true;
}
void FbRun::setForeground(const XColor &color) {
XSetForeground(m_display, m_gc, color.pixel);
void FbRun::setForeground(const FbTk::Color &color) {
XSetForeground(m_display, m_gc, color.pixel());
redrawLabel();
}
void FbRun::setBackground(const XColor &color) {
XSetWindowBackground(m_display, m_win, color.pixel);
void FbRun::setBackground(const FbTk::Color &color) {
m_win.setBackgroundColor(color);
redrawLabel();
}
@ -127,36 +131,28 @@ void FbRun::setText(const string &text) {
}
void FbRun::setTitle(const string &title) {
assert(m_win);
XStoreName(m_display, m_win, const_cast<char *>(title.c_str()));
m_win.setName(title.c_str());
}
void FbRun::move(int x, int y) {
XMoveWindow(m_display, m_win, x, y);
m_win.move(x, y);
}
void FbRun::resize(size_t width, size_t height) {
assert(m_win);
XResizeWindow(m_display, m_win, width, height);
m_width = width;
m_height = height;
m_win.resize(width, height);
setNoMaximize();
}
void FbRun::show() {
assert(m_win);
XMapWindow(m_display, m_win);
m_win.show();
}
void FbRun::hide() {
assert(m_win);
XUnmapWindow(m_display, m_win);
m_win.hide();
}
void FbRun::redrawLabel() {
assert(m_win);
XClearWindow(m_display, m_win);
m_win.clear();
drawString(m_bevel/2, m_font.ascent() + m_bevel/2,
m_runtext.c_str(), m_runtext.size());
@ -164,44 +160,19 @@ void FbRun::redrawLabel() {
void FbRun::drawString(int x, int y,
const char *text, size_t len) {
assert(m_win);
assert(m_gc);
// check right boundary
// and adjust text drawing
// check right boundary and adjust text drawing
size_t text_width = m_font.textWidth(text, len);
size_t startpos = 0;
if (text_width > m_width) {
if (text_width > m_win.width()) {
for (; startpos < len; ++startpos) {
if (m_font.textWidth(text+startpos, len-startpos) < m_width)
if (m_font.textWidth(text+startpos, len-startpos) < m_win.width())
break;
}
}
m_font.drawText(m_win, DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y);
}
void FbRun::createWindow(int x, int y, size_t width, size_t height) {
m_win = XCreateSimpleWindow(m_display, // display
DefaultRootWindow(m_display), // parent windows
x, y,
width, height,
1, // border_width
0, // border
WhitePixel(m_display, DefaultScreen(m_display))); // background
if (m_win == None)
throw string("Failed to create FbRun window!");
XSelectInput(m_display, m_win, KeyPressMask|ExposureMask);
FbTk::EventManager::instance()->registerEventHandler(*this, m_win);
setNoMaximize();
m_width = width;
m_height = height;
m_font.drawText(m_win.window(), DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y);
}
void FbRun::keyPressEvent(XKeyEvent &ke) {
@ -211,6 +182,7 @@ void FbRun::keyPressEvent(XKeyEvent &ke) {
if (ks == XK_Escape) {
m_end = true;
hide();
FbTk::App::instance()->end(); // end program
return; // no more processing
} else if (ks == XK_Return) {
run(m_runtext);
@ -241,27 +213,16 @@ void FbRun::exposeEvent(XExposeEvent &ev) {
redrawLabel();
}
void FbRun::getSize(size_t &width, size_t &height) {
XWindowAttributes attr;
XGetWindowAttributes(m_display, m_win, &attr);
width = attr.width;
height = attr.height;
}
void FbRun::setNoMaximize() {
size_t width, height;
getSize(width, height);
// we don't need to maximize this window
XSizeHints sh;
sh.flags = PMaxSize | PMinSize;
sh.max_width = width;
sh.max_height = height;
sh.min_width = width;
sh.min_height = height;
XSetWMNormalHints(m_display, m_win, &sh);
sh.max_width = m_win.width();
sh.max_height = m_win.height();
sh.min_width = m_win.width();
sh.min_height = m_win.height();
XSetWMNormalHints(m_display, m_win.window(), &sh);
}
void FbRun::prevHistoryItem() {

View file

@ -19,13 +19,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbRun.hh,v 1.7 2002/11/27 21:56:02 fluxgen Exp $
// $Id: FbRun.hh,v 1.8 2002/12/05 00:07:38 fluxgen Exp $
#ifndef FBRUN_HH
#define FBRUN_HH
#include "EventHandler.hh"
#include "Font.hh"
#include "FbWindow.hh"
#include <string>
#include <vector>
@ -42,16 +43,16 @@ public:
void setTitle(const std::string &title);
void move(int x, int y);
void resize(size_t width, size_t height);
size_t height() const { return m_height; }
size_t width() const { return m_width; }
size_t height() const { return m_win.height(); }
size_t width() const { return m_win.width(); }
/// hide window
void hide();
/// show window
void show();
/// load and reconfigure for new font
bool loadFont(const std::string &fontname);
void setForeground(const XColor &color);
void setBackground(const XColor &color);
void setForeground(const FbTk::Color &color);
void setBackground(const FbTk::Color &color);
void setAntialias(bool val) { m_font.setAntialias(val); }
const FbTk::Font &font() const { return m_font; }
/// execute command and exit
@ -82,10 +83,9 @@ private:
void setNoMaximize();
FbTk::Font m_font; ///< font used to draw command text
Window m_win; ///< toplevel window
FbTk::FbWindow m_win; ///< toplevel window
Display *m_display; ///< display connection
std::string m_runtext; ///< command to execute
size_t m_width, m_height; ///< size of window
int m_bevel; ///< distance to window edge from font in pixels
GC m_gc; ///< graphic context
bool m_end; ///< marks when this object is done

View file

@ -19,11 +19,12 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: main.cc,v 1.7 2002/11/27 21:54:11 fluxgen Exp $
// $Id: main.cc,v 1.8 2002/12/05 00:07:39 fluxgen Exp $
#include "FbRun.hh"
#include "App.hh"
#include "StringUtil.hh"
#include "Color.hh"
#include <string>
#include <iostream>
@ -45,7 +46,7 @@ void showUsage(const char *progname) {
" -fg [color name] Foreground text color"<<endl<<
" -bg [color name] Background color"<<endl<<
" -a Antialias"<<endl<<
" -hf [history file] History file to load (default ~/.fluxbox/history)"<<endl<<
" -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<<
" -help Show this help"<<endl<<endl<<
"Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
}
@ -105,8 +106,6 @@ int main(int argc, char **argv) {
try {
FbTk::App application(display_name.c_str());
Display *disp = application.display();
FbRun fbrun;
if (fontname.size() != 0) {
@ -118,25 +117,11 @@ int main(int argc, char **argv) {
// get color
XColor xc_foreground, xc_background;
if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
foreground.c_str(),
&xc_foreground) == 0) {
cerr<<"Faild to lookup color: "<<foreground<<endl;
}
FbTk::Color fg_color(foreground.c_str(), 0);
FbTk::Color bg_color(background.c_str(), 0);
if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
background.c_str(),
&xc_background) == 0) {
cerr<<"Faild to lookup color: "<<background<<endl;
}
XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
&xc_foreground);
XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
&xc_background);
fbrun.setForeground(xc_foreground);
fbrun.setBackground(xc_background);
fbrun.setForeground(fg_color);
fbrun.setBackground(bg_color);
if (set_height)
fbrun.resize(fbrun.width(), height);