/uwm/tags/RELEASE-0.2.10/uwm/widgets.c

# · C · 221 lines · 169 code · 24 blank · 28 comment · 18 complexity · 903634cc818e7ac1076fa855da6d3837 MD5 · raw file

  1. /*** WIDGETS.C: Contains routines for the UWM-widget-drawing ***/
  2. /* ########################################################################
  3. uwm - THE ude WINDOW MANAGER
  4. ########################################################################
  5. Copyright (c) : Christian Ruppert
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ######################################################################## */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <X11/Xlib.h>
  22. #include <string.h>
  23. #include "uwm.h"
  24. #include "init.h"
  25. extern Display *disp;
  26. extern UDEScreen TheScreen;
  27. extern InitStruct InitS;
  28. extern UltimateContext *FocusWin;
  29. void DrawBevel(Drawable win,int x1,int y1,int x2,int y2,int width,GC NW,GC SE)
  30. {
  31. int a;
  32. for(a=0;a<width;a++){
  33. XDrawLine(disp,win,NW,x1+a,y1+a,x2-a-1,y1+a);
  34. XDrawLine(disp,win,NW,x1+a,y1+a+1,x1+a,y2-a);
  35. XDrawLine(disp,win,SE,x1+a+1,y2-a,x2-1-a,y2-a);
  36. XDrawLine(disp,win,SE,x2-a,y1+a,x2-a,y2-a);
  37. }
  38. }
  39. /* Draw bevels onto a window. I use this function rather
  40. than the widgets.c DrawBevel function because I want to draw a
  41. shadowed border too, and this way I can have other effects.
  42. Partially by Adam Sampson. */
  43. void DrawFrameBevel(UltimateContext *uc)
  44. {
  45. XGCValues xgcv;
  46. int xa, ya, xb, yb, xc, yc, xd, yd, i;
  47. GC LightGC, ShadowGC;
  48. int Active = uc->flags & ACTIVE_BORDER;
  49. if(!TheScreen.FrameBevelWidth) return;
  50. xgcv.function=GXcopy;
  51. xgcv.foreground=Active
  52. ? TheScreen.ActiveLight[TheScreen.desktop.ActiveWorkSpace]\
  53. :TheScreen.InactiveLight[TheScreen.desktop.ActiveWorkSpace];
  54. xgcv.line_width=0;
  55. xgcv.line_style=LineSolid;
  56. xgcv.cap_style=CapButt;
  57. LightGC=XCreateGC(disp,uc->frame,GCFunction|GCForeground|\
  58. GCCapStyle|GCLineWidth|GCLineStyle,&xgcv);
  59. xgcv.function=GXcopy;
  60. xgcv.foreground=Active
  61. ? TheScreen.ActiveShadow[TheScreen.desktop.ActiveWorkSpace]\
  62. : TheScreen.InactiveShadow[TheScreen.desktop.ActiveWorkSpace];
  63. xgcv.line_width=0;
  64. xgcv.line_style=LineSolid;
  65. xgcv.cap_style=CapButt;
  66. ShadowGC=XCreateGC(disp,uc->frame,GCFunction|GCForeground|\
  67. GCCapStyle|GCLineWidth|GCLineStyle,&xgcv);
  68. if(!(uc->flags & SHAPED)){
  69. xc = yc = 0;
  70. xd = uc->Attr.width - 1;
  71. yd = uc->Attr.height - 1;
  72. for(i=0; i<TheScreen.FrameBevelWidth; i++) {
  73. xa = xc + i; xb = xd - i;
  74. ya = yc + i; yb = yd - i;
  75. XDrawLine(disp,uc->border, i?LightGC:ShadowGC, xa, ya, xb, ya);
  76. XDrawLine(disp,uc->border, i?ShadowGC:TheScreen.blackcontext,xb,ya,xb,yb);
  77. XDrawLine(disp,uc->border, i?ShadowGC:TheScreen.blackcontext,xb,yb,xa,yb);
  78. XDrawLine(disp,uc->border, i?LightGC:ShadowGC, xa, yb, xa, ya);
  79. }
  80. if(((i=(uc->BorderWidth-TheScreen.FrameBevelWidth-1)) > 3) &&\
  81. (InitS.BorderTitleFlags & BT_GROOVE)){
  82. i=i/2+TheScreen.FrameBevelWidth;
  83. if(InitS.BorderTitleFlags & BT_CENTER_TITLE) {
  84. DrawBevel(uc->border,i-1,2*uc->BorderWidth,i,uc->Attr.height-\
  85. 2*uc->BorderWidth,1,ShadowGC,LightGC);
  86. DrawBevel(uc->border,2*uc->BorderWidth,i-1,uc->Attr.width-\
  87. 2*uc->BorderWidth,i,1,ShadowGC,LightGC);
  88. DrawBevel(uc->border,uc->Attr.width-i-1,2*uc->BorderWidth,\
  89. uc->Attr.width-i,uc->Attr.height-2*uc->BorderWidth,\
  90. 1,ShadowGC,LightGC);
  91. DrawBevel(uc->border,2*uc->BorderWidth,uc->Attr.height-i-1,\
  92. uc->Attr.width-2*uc->BorderWidth,uc->Attr.height-i\
  93. ,1,ShadowGC,LightGC);
  94. } else {
  95. DrawBevel(uc->border,i-1,i-1,uc->Attr.width-i,uc->Attr.height-i,1,\
  96. ShadowGC,LightGC);
  97. DrawBevel(uc->border,i,i,uc->Attr.width-i-1,uc->Attr.height-i-1,1,\
  98. LightGC,ShadowGC);
  99. }
  100. }
  101. if(InitS.BorderTitleFlags&BT_LINE)
  102. DrawBevel(uc->border,uc->BorderWidth-1,uc->BorderWidth+TheScreen.\
  103. TitleHeight-1,uc->Attr.width-uc->BorderWidth,\
  104. uc->Attr.height-uc->BorderWidth,1,\
  105. TheScreen.blackcontext,TheScreen.blackcontext);
  106. }
  107. XFreeGC(disp, LightGC);
  108. XFreeGC(disp, ShadowGC);
  109. }
  110. void DrawTitle(UltimateContext *uc)
  111. {
  112. XGCValues xgcv;
  113. GC LightGC, ShadowGC, TextGC;
  114. int i;
  115. int Active = uc->flags & ACTIVE_BORDER;
  116. xgcv.function=GXcopy;
  117. xgcv.foreground=Active
  118. ? TheScreen.ActiveLight[TheScreen.desktop.ActiveWorkSpace]\
  119. : TheScreen.InactiveLight[TheScreen.desktop.ActiveWorkSpace];
  120. xgcv.line_width=0;
  121. xgcv.line_style=LineSolid;
  122. xgcv.cap_style=CapButt;
  123. LightGC=XCreateGC(disp,uc->frame,GCFunction|GCForeground|\
  124. GCCapStyle|GCLineWidth|GCLineStyle,&xgcv);
  125. xgcv.function=GXcopy;
  126. xgcv.foreground=Active
  127. ? TheScreen.ActiveShadow[TheScreen.desktop.ActiveWorkSpace]\
  128. : TheScreen.InactiveShadow[TheScreen.desktop.ActiveWorkSpace];
  129. xgcv.line_width=0;
  130. xgcv.line_style=LineSolid;
  131. xgcv.cap_style=CapButt;
  132. ShadowGC=XCreateGC(disp,uc->frame,GCFunction|GCForeground|\
  133. GCCapStyle|GCLineWidth|GCLineStyle,&xgcv);
  134. xgcv.function=GXcopy;
  135. xgcv.foreground=Active
  136. ? TheScreen.ActiveTitleFont[TheScreen.desktop.ActiveWorkSpace]
  137. : TheScreen.InactiveTitleFont\
  138. [TheScreen.desktop.ActiveWorkSpace];
  139. xgcv.font=TheScreen.TitleFont->fid;
  140. TextGC=XCreateGC(disp,uc->frame,GCFunction|GCForeground|GCFont,&xgcv);
  141. XClearWindow(disp,uc->title.win);
  142. if(uc->flags & SHAPED) {
  143. DrawBevel(uc->title.win, 0, 0, uc->title.width - 1, uc->title.height - 1,
  144. 1, TheScreen.blackcontext, TheScreen.blackcontext);
  145. DrawBevel(uc->title.win, 1, 1, uc->title.width - 2, uc->title.height - 2,
  146. 1, LightGC, ShadowGC);
  147. } else {
  148. if((i=(uc->BorderWidth-TheScreen.FrameBevelWidth-1)) <= 3) i=2;
  149. i=i/2+TheScreen.FrameBevelWidth;
  150. if(InitS.BorderTitleFlags & BT_GROOVE){
  151. XDrawLine(disp, uc->title.win, LightGC,
  152. (InitS.BorderTitleFlags & BT_CENTER_TITLE) ? 2 : 0,
  153. uc->title.height-2, uc->title.width-2, uc->title.height-2);
  154. XDrawLine(disp, uc->title.win, LightGC, uc->title.width-2, 0,
  155. uc->title.width-2, uc->title.height-2);
  156. XDrawPoint(disp, uc->title.win, LightGC, uc->title.width-1, 0);
  157. if(InitS.BorderTitleFlags & BT_CENTER_TITLE) {
  158. XDrawLine(disp, uc->title.win, ShadowGC,1,0,1, uc->title.height-2);
  159. XDrawPoint(disp, uc->title.win, LightGC, 0, 0);
  160. } else {
  161. XDrawPoint(disp, uc->title.win, LightGC, 0, uc->title.height-1);
  162. }
  163. }
  164. if(((TheScreen.TitleHeight + uc->BorderWidth - i) <= uc->title.height) &&
  165. (InitS.BorderTitleFlags & BT_LINE)) {
  166. XDrawLine(disp, uc->title.win, TheScreen.blackcontext,
  167. (InitS.BorderTitleFlags & BT_CENTER_TITLE)
  168. ? 0 : (uc->BorderWidth - i - 1),
  169. uc->title.height - 1, uc->title.width - 1,
  170. uc->title.height - 1);
  171. XDrawLine(disp, uc->title.win, TheScreen.blackcontext,
  172. uc->title.width - 1,
  173. uc->BorderWidth - i - 1 + TheScreen.TitleHeight,
  174. uc->title.width - 1, uc->title.height-1);
  175. if(InitS.BorderTitleFlags & BT_CENTER_TITLE)
  176. XDrawLine(disp,uc->title.win, TheScreen.blackcontext, 0,
  177. uc->BorderWidth - i - 1 + TheScreen.TitleHeight, 0,
  178. uc->title.height - 1);
  179. }
  180. }
  181. if(uc->title.name) XDrawString(disp, uc->title.win, TextGC,
  182. ((uc->flags & SHAPED)
  183. || (InitS.BorderTitleFlags & BT_CENTER_TITLE))
  184. ? 5 : 2, ((uc->flags & SHAPED) ? 3 : 0)
  185. + TheScreen.TitleFont->ascent, uc->title.name,
  186. strlen(uc->title.name));
  187. XFreeGC(disp, LightGC);
  188. XFreeGC(disp, ShadowGC);
  189. XFreeGC(disp, TextGC);
  190. }