1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Pen.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
34 # include <X11/Xft/Xft.h>
44 const Display
&_display
;
46 PenLoader(const Display
&display_
)
49 const Display
&display(void) const
51 ::Display
*XDisplay(void) const
52 { return _display
.XDisplay(); }
55 static PenLoader
*penloader
= 0;
57 void createPenLoader(const Display
&display
)
59 assert(penloader
== 0);
60 penloader
= new PenLoader(display
);
62 void destroyPenLoader(void)
70 bt::Pen::Pen(unsigned int screen_
)
71 : _screen(screen_
), _function(GXcopy
), _linewidth(0),
72 _subwindow(ClipByChildren
), _dirty(false), _gc(0), _xftdraw(0)
75 bt::Pen::Pen(unsigned int screen_
, const Color
&color_
)
76 : _screen(screen_
), _color(color_
), _function(GXcopy
), _linewidth(0),
77 _subwindow(ClipByChildren
), _dirty(false), _gc(0), _xftdraw(0)
83 XFreeGC(penloader
->XDisplay(), _gc
);
88 XftDrawDestroy(_xftdraw
);
93 void bt::Pen::setColor(const Color
&color_
)
99 void bt::Pen::setGCFunction(int function
)
101 _function
= function
;
105 void bt::Pen::setLineWidth(int linewidth
)
107 _linewidth
= linewidth
;
111 void bt::Pen::setSubWindowMode(int subwindow
)
113 _subwindow
= subwindow
;
117 ::Display
*bt::Pen::XDisplay(void) const
118 { return penloader
->XDisplay(); }
120 const bt::Display
&bt::Pen::display(void) const
121 { return penloader
->display(); }
123 const GC
&bt::Pen::gc(void) const
125 if (!_gc
|| _dirty
) {
127 gcv
.foreground
= _color
.pixel(_screen
);
128 gcv
.function
= _function
;
129 gcv
.line_width
= _linewidth
;
130 gcv
.subwindow_mode
= _subwindow
;
132 _gc
= XCreateGC(penloader
->XDisplay(),
133 penloader
->display().screenInfo(_screen
).rootWindow(),
141 XChangeGC(penloader
->XDisplay(),
155 XftDraw
*bt::Pen::xftDraw(Drawable drawable
) const
159 const ScreenInfo
&screeninfo
= penloader
->display().screenInfo(_screen
);
160 _xftdraw
= XftDrawCreate(penloader
->XDisplay(),
163 screeninfo
.colormap());
164 } else if (XftDrawDrawable(_xftdraw
) != drawable
) {
165 XftDrawChange(_xftdraw
, drawable
);
167 assert(_xftdraw
!= 0);