wmi

git clone git://oldgit.suckless.org/wmi/
Log | Files | Refs | LICENSE

widget.cpp (2089B)


      1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us>
      2 // See LICENSE for license details.
      3 
      4 #include "widget.h"
      5 
      6 #include "cursors.h"
      7 #include "kernel.h"
      8 #include "monitor.h"
      9 #include "xcore.h"
     10 #include "xfont.h"
     11 
     12 Widget::Widget(Monitor *monitor, Rectangle *rect, bool initWindowAndGC)
     13     : Rectangle(*rect)
     14 {
     15     monitor_ = monitor;
     16     isVisible_ = false;
     17     if (initWindowAndGC) {
     18         initWindow();
     19         initGC();
     20     }
     21     else {
     22         window_ = 0;
     23         gc_ = 0;
     24     }
     25 }
     26 
     27 Widget::~Widget() {
     28     XCORE->free(gc_);
     29     XCORE->destroy(window_);
     30 }
     31 
     32 Monitor *Widget::monitor() const  {
     33     return monitor_;
     34 }
     35 
     36 Window Widget::window() const {
     37     return window_;
     38 }
     39 
     40 GC Widget::gc() const {
     41     return gc_;
     42 }
     43 
     44 void Widget::show() {
     45     isVisible_ = true;
     46     XCORE->showRaised(window_);
     47 }
     48 
     49 void Widget::hide() {
     50     isVisible_ = false;
     51     XCORE->hide(window_);
     52 }
     53 
     54 bool Widget::isVisible() const {
     55     return isVisible_;
     56 }
     57 
     58 void Widget::initWindow() {
     59     Kernel *kernel = KERNEL;
     60 
     61     XSetWindowAttributes attr;
     62     attr.override_redirect = 1;
     63     attr.background_pixmap = ParentRelative;
     64 
     65     window_ = XCORE->createWindow(monitor_->rootWindow(), &attr,
     66                                   x(), y(), width(), height(),
     67                                   CWOverrideRedirect | CWBackPixmap);
     68     XCORE->selectEvents(window_,
     69                  ExposureMask | ButtonPressMask | ButtonReleaseMask |
     70                  PointerMotionMask | SubstructureRedirectMask |
     71                  SubstructureNotifyMask);
     72 
     73     kernel->installCursor(Cursors::NORMAL_CURSOR, window_);
     74 }
     75 
     76 void Widget::initGC() {
     77     unsigned long mask = 0;
     78     XGCValues gcv;
     79 
     80     mask = GCForeground | GCBackground |
     81            GCFunction | GCLineWidth | GCLineStyle;
     82 
     83     gcv.function = GXcopy;
     84     gcv.line_width = 1;
     85     gcv.line_style = LineSolid;
     86     if (monitor_->font()->type() == WFont::NORMAL) {
     87         gcv.font = ((XFont *)monitor_->font())->font()->fid;
     88         mask |= GCFont;
     89     }
     90 
     91     gc_ = XCORE->createGC(window_, mask, &gcv);
     92 }
     93 
     94 void Widget::resize() {
     95     XCORE->moveResize(window_, this);
     96 }