From cee882874ec2a05ed37343821486802916a041da Mon Sep 17 00:00:00 2001 From: gabrielfin Date: Sun, 2 Jun 2019 14:56:54 -0300 Subject: [PATCH] Pick up icons directly from the theme Implementation of an icon finder, that looks for icons that match with certain name patterns, inside the theme folder --- .../mate-window-applets/Black/index.theme | 27 --- .../mate-window-applets/White/close/close.png | Bin 1056 -> 0 bytes .../White/close/close_hovered.png | Bin 1345 -> 0 bytes .../mate-window-applets/White/index.theme | 27 --- .../White/maximize/maximize.png | Bin 745 -> 0 bytes .../White/maximize/maximize_hovered.png | Bin 808 -> 0 bytes .../White/maximize/unmaximize.png | Bin 1366 -> 0 bytes .../White/maximize/unmaximize_hovered.png | Bin 1408 -> 0 bytes .../White/minimize/minimize.png | Bin 512 -> 0 bytes .../White/minimize/minimize_hovered.png | Bin 608 -> 0 bytes .../mate-window-applets}/close.png | Bin .../mate-window-applets/close_prelight.png} | Bin .../mate-window-applets}/maximize.png | Bin .../maximize_prelight.png} | Bin .../mate-window-applets}/minimize.png | Bin .../minimize_prelight.png} | Bin .../mate-window-applets}/unmaximize.png | Bin .../unmaximize_prelight.png} | Bin install-icons.sh | 8 +- window-buttons-applet/meson.build | 2 +- window-buttons-applet/window-button.vala | 150 +++++--------- .../window-buttons-applet.vala | 83 ++++---- .../window-buttons-theme.vala | 189 ++++++++++++++++++ 23 files changed, 280 insertions(+), 206 deletions(-) delete mode 100644 data/icons/mate-window-applets/Black/index.theme delete mode 100644 data/icons/mate-window-applets/White/close/close.png delete mode 100644 data/icons/mate-window-applets/White/close/close_hovered.png delete mode 100644 data/icons/mate-window-applets/White/index.theme delete mode 100644 data/icons/mate-window-applets/White/maximize/maximize.png delete mode 100644 data/icons/mate-window-applets/White/maximize/maximize_hovered.png delete mode 100644 data/icons/mate-window-applets/White/maximize/unmaximize.png delete mode 100644 data/icons/mate-window-applets/White/maximize/unmaximize_hovered.png delete mode 100644 data/icons/mate-window-applets/White/minimize/minimize.png delete mode 100644 data/icons/mate-window-applets/White/minimize/minimize_hovered.png rename data/{icons/mate-window-applets/Black/close => pixmaps/mate-window-applets}/close.png (100%) rename data/{icons/mate-window-applets/Black/close/close_hovered.png => pixmaps/mate-window-applets/close_prelight.png} (100%) rename data/{icons/mate-window-applets/Black/maximize => pixmaps/mate-window-applets}/maximize.png (100%) rename data/{icons/mate-window-applets/Black/maximize/maximize_hovered.png => pixmaps/mate-window-applets/maximize_prelight.png} (100%) rename data/{icons/mate-window-applets/Black/minimize => pixmaps/mate-window-applets}/minimize.png (100%) rename data/{icons/mate-window-applets/Black/minimize/minimize_hovered.png => pixmaps/mate-window-applets/minimize_prelight.png} (100%) rename data/{icons/mate-window-applets/Black/maximize => pixmaps/mate-window-applets}/unmaximize.png (100%) rename data/{icons/mate-window-applets/Black/maximize/unmaximize_hovered.png => pixmaps/mate-window-applets/unmaximize_prelight.png} (100%) create mode 100644 window-buttons-applet/window-buttons-theme.vala diff --git a/data/icons/mate-window-applets/Black/index.theme b/data/icons/mate-window-applets/Black/index.theme deleted file mode 100644 index 65b38ef..0000000 --- a/data/icons/mate-window-applets/Black/index.theme +++ /dev/null @@ -1,27 +0,0 @@ -[Icon Theme] -Name = Black -Comment = Black theme for WindowButtons - -# Directory list -Directories=close,minimize,maximize - -[close] -Context=close -Size=256 -MinSize=8 -MaxSize=512 -Type=fixed - -[minimize] -Context=minimize -Size=256 -MinSize=8 -MaxSize=512 -Type=Scalable - -[maximize] -Context=maximize -Size=256 -MinSize=8 -MaxSize=512 -Type=Scalable diff --git a/data/icons/mate-window-applets/White/close/close.png b/data/icons/mate-window-applets/White/close/close.png deleted file mode 100644 index 79c860f47423b8a7cf7cbaa52a9ce656e2ad82f5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1056 zcmeAS@N?(olHy`uVBq!ia0vp^KR}p+4M-lmsLc(e*pj^6T^Rm@;DWu&Cj&(|3p^r= z85p>QL70(Y)*K0-AbW|YuPggQ78y}f@X^nEp!tq|fWU_Zw!tvtvzo(9p;{(T97#-kJNe{2eRy#fk5Wi!J!z!p~RCKyh&yn7FAqNF1mGAufD( zvMi6x*an>D^_7f=JW+>$Ax8K#(n?!x!@pB z6_3n?2X8JvnRS~L$TTQ$XfF1d{J4pkjSp;OBbb521i8RL)BC>Oub;_vHK!GiZ2qOZ z3E{C>GD2qCx%uY30D4~)=rQM}XJrQuf^1!o(wtqyaRca}ibX&}c`iPfCBtL_Q|oND zL#>?~K1*tsP;l`DPzgo}XC1{EB~>xQxw3aL_(;o4gwo$3O?g6gw|fD~I^f zp*cIxWGBdJ2@ilyGY`osf@*2YFF4x^R0a-mlO506f_&dK0bL3V&Yx`8?+7e82@OS! z>knp0H<D>F!L2+ffjh&dIAl_B^d>Gd0A)Ofd(5WHbL=w5ET6oCYa%7 z@Ka>Uwy*AQetk=TC8%?TXZL>l4RdP)Tl)NG*MP=CQskWMSpb5+Zaz@5o3Q*~ lsrt;>GU752FEj@4We``5o!L9fH3gJWJzf1=);T3K0RWkCo7w;X diff --git a/data/icons/mate-window-applets/White/close/close_hovered.png b/data/icons/mate-window-applets/White/close/close_hovered.png deleted file mode 100644 index 57c10430285238770d6236aed5ba5b54abcb228e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1345 zcmZWpZA@BM7{=f(qJlWGtO5Mk+#uWHG#gZ`b?C$)X+UecwsRV7BNb&Lh3mJOsLLAX zDp{#Nh95J!&UA~KCZo!#5!z)=GpxiYDp2q2RY_IsQ0rGGJNLTzXSq4&s!0gNPAEJ-E(>CbwF7x=?hSI+@cSmF6ga7syWu}lerR{|kLExQcM@*~R&VR@uT zEXl}!S4JWb{BMhe$>%HP*Il1xMqQ+(p3SMRdk?;v`J##T+V?*W?Oj@(3ccs3pK4(` zuY`?WBUbG{ds$mYgsA!6J*2;fx@o*HJF?1eUYdGid*wmst|?>j&AXeF5M89w9^Xzw3Ueo0&o6N-T|*o}=$JQL-OC_SV`YngkngYjYb|)?N!p@LMAl zqVjFLJ*{xkNrA%SwT&@VJ?xb`y19Fa@wVg!A|o4ff6;$!uXC+fy|B_Z<&eUY$6@vM zBDK}^ld0X^Y4PLy!WLdchc7J)W^o7V6l!*B zmoRtlN6lSLxMt7M;;|4eM3LI{dH)#25x>2o9u(i9}4b?S(y6&%qnGHTk$S7oI}15;n~^Hp=1Roy7xm zQjWx0nsI1&xoM?06Kt1hL=ut2-A#>t(xh}Nk6SoqbKuP(ro$>j2xE7Pt*c>1m57&w zcw6(zKyj~spgU~=rC`*=7;mxr5AF_mBNh$|Xw~)aPY=+;Vu2w1h}UCtAzUR%ozv?f zTcX2ceNMmY=eU}H!;Ru?!AM1Y19mmC#alc3YiojPY31BDd*?`LKv+(>I$f1FPiG0F z0qLsF2lQ-B_gEs97t}qt{NoD%HBGKC(D|%ZhY42F-kl_5``*PS#Pi(2~@7$0bZrW9%!E)l`pvm25^p*R< zOXj9~#(;E|X8;rox#x@dS%;zKf?lUkS$oIY-C(X>VrIYks7NUZcVIEPabp7{0@03h zfeF*t_e+6=BvB$hpO(O2wYlX=@G_z10uJy2R!W*V{G%~1r~>YoNC5o+*35r&QL70(Y)*K0-AbW|YuPggQ78x;7@gTnmg+L+M%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6_|fq}`_)5S5Q;?~<+hC&SrJg$z9pZp8&Te?)F(eduumH$4l zaW7uQ_h7c4aKiz{MrI~<7CsIc0gFHWvl6WArS2SJi7Rk;&~U&Jh>@g0N)*5nU_pdF zg#r`_7CxAPAk|1ZK(;_^f(bSgYyJ*Skb@fMJ~=ScNZ9wz(z=JN?DJpXbRLSiw07PH z9rklAGjC1dyrZoT4j`ECpaDy!myyF7HAvB7hCK7pVg?jtdpu?(tTbRmi~MD~7_vTb Vd~-hAwGfozJYD@<);T3K0RXZ!$x#3R diff --git a/data/icons/mate-window-applets/White/maximize/maximize_hovered.png b/data/icons/mate-window-applets/White/maximize/maximize_hovered.png deleted file mode 100644 index de70882a2164f4b3da343fd270579813b1b93c3a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 808 zcmeAS@N?(olHy`uVBq!ia0vp^KR}p+4M-lmsLc(e*pj^6U4S$Y{B+)352QE?JR*x3 z7`TN&n2}-D90{Nxdx@v7EBiwh88LJ9%c{@*0)=EVLn2C?^K)}k^GbkR1_tM%)Wnk1 z6ovB4k_-iRPv3wPy;ODv2BscQ7srr_TW{|=@--QVxCYLD`EUE5m?o7F%`bB{GOvlL z^Hf;&mb+rvc2$N(W+rwPJ`NcH3x$Fk=Qps}m%nmsR(V}B@$-3~BQF!0z|sgM4i6d* zI07*vLLWpgNP@Ak8CgQ10AwggqOr0~H6l8?yMYsE6U;U&I*^S5T8yv*VHDJ2kc-yj z%lz=s6`pJ{{aH6B-?kSxU3K`~zI}SLQf4;i?#<;;vna@EDz@FN!NOM^S905I+lvQs zVBbUBL)cn`BcTCN|M~0xgMS}d&v@joipzd^T(;`UshMfIe`+ar>mdKI;Vst0EUe67XSbN diff --git a/data/icons/mate-window-applets/White/maximize/unmaximize.png b/data/icons/mate-window-applets/White/maximize/unmaximize.png deleted file mode 100644 index 9ddafc4a7d87f3588769a5c7438990ea90369b23..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1366 zcmeAS@N?(olHy`uVBq!ia0vp^KR}p+4M-lmsLc(e*pj^6T^Rm@;DWu&Cj&(|3p^r= z85p>QL70(Y)*K0-AbW|YuPggQ78x-WtBYq&ZvzU+W`;zRIOpf)rskCZxeN@>MX8A; zsVNHOnI#zt?w-B@DSD~w3=Ay0JY5_^DsH{KdoVBBRif=-zRdQ}s09mS6%}u6cqp~w zKX<}mv5k$aOS3YknDxC)ylB{Srjyqb_f0uB3m<*9UVr{Z;oYEYUV~+=f(-{4 z8=0BdS@`apxy12o^%SGmx1Z}9e0u;F2gz~B2v{f-I6MGhxCDm`LINb%3^NI&8m0rP z8e#=R5MmVE7-aJs4me^r{{Xwj*05lPYOwte<7~zCmh$|S*)t_5>v!Vcm(0!@cbfw; z+fye^R^gvqGxN!JmHe!=xBE-fb-v}DephnW`cH2C?qB(l*}B#DvoG@T-`Y0!?cYE7 zyD!_T?(`{|`sB-jv^{ez-fubkw&?%2cR$~p=r}hyXV?4bWz~I^xBBX5&iI)peSfR- zq&1V?yt`aF+c)?5+>+_K-~94--Tu09UHI*f@BX;IwTo5%x##y>i|oynceed6ozz_x zzyHO%?$GkNch6h?ur9sbSS`wzw#QeJVxyRkI0&3jU<+*HWC-#|&iyddGh zf&U=J2W{o1pH|=4q`XUZ9IyUR4Cd*XR~GJR2_ zERWg#Ef+l4bN#uy-K{?n58@>hfhz0MT@3Ob06kI2Y;Owk&vZAI&!JwL=A3u#pG-WK z_e*Qnfy4)@zgmF~_by2QvW{^i-cbb$R+&0Ul=JTcYBTu|wHm0*)}o+YTFl~3?ms?0 zW@|x3sv^BKcYj`Q zU3>QZyZT-C?#*^B+kETpes#}zPyV`h*!z6){l3*+<)`V%%Vl%JJZm6o%g4t zM|Su8a=*9dUEUgB|D-7IKdT_~^T``s{%<+b3(7$5I=uQL70(Y)*K0-AbW|YuPggQ78x-k?d4D6KOLn2C?^K)}k^GbkR1_tM%)Wnk1 z6ovB4k_-iRPv3wPy;ODv29_tDE{-7;x8B}8n-}dWbL?Tc(Du-%1q)*p6>n^KD7E81 zcfw(@jSIQCv`oBa^H)cd@F*8Q3ch7xHP5C$=7)v0a>TlzQ;YQHhbQD5WQ2)>3;xP*WOLINxZ(*aTq(*act zu>v9pF$!)BviXdS&DhOv!mPG( ztDa1q^ftHZZd&l|>wUW)_m%Oj-+lV)O26>i|GvHMzm;1x_sQpX<&UpU%i@T z{`Rk@-)-CR#&5Ij{Jr~wx6AHGf0%Hvo7ubMgG5cy$*L?DgNz5B`^=Rj%s&(>Hx)9o zv+?~Y2Ql^=DMhT?X?`JM(P7(rP4guMb*|speJAJOL%IBedwoUO>UiFHnn_f2=5g{f z>t8f?V`l3_wtRPl zWWmwf&2?vTjzQLgtK9PvI^mIw7CUW0UX^+U64U?tvN7)#vgmmo^uS7SZQSLj#9oJ7L-YlJbPI0O9=8vRjdttVDLdq#^OO6 zD_{HB*AEOfBsU)3A;%$eZ0mRD$Y=jzOqNbj_uS|8Y1!LJPZmZ0k1s11dA%*=MoGEC z--o5Q^*z_^{%qfJIrrAOlKbUX&K6Ep*?KL!`q3WacKqFf^Z$3qmKzq{`K)qYZCZBk+S5@^dN_Tzy{dex$x%P@l5AH~Mf7z{?2g)=vHX1dx+GpJVf86PG z#hr(hGST2Xik63{o)t;S>S!efj;wxXQBbxi>jqYEF$5|j5>DOM%8>t|YFTmuR1kW) L`njxgN@xNAp3+aL diff --git a/data/icons/mate-window-applets/White/minimize/minimize.png b/data/icons/mate-window-applets/White/minimize/minimize.png deleted file mode 100644 index 9193380ec3737a9b659730e9312d031067a01f02..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmeAS@N?(olHy`uVBq!ia0vp^KR}p+4M-lmsLc(e*pj^6U4S$Y{B+)352QE?JR*x3 z7`TN&n2}-D90{Nxdx@v7EBiwh8F3bw>Fo^nfI_mFArU3c`MJ5Nc_lzD1A}u>YGO%h zib8p2Nrr;Er*A-tUMf2S17nJ(i(^Q|t+$sqaxxh3FgsfRe!nK?!KIdh>#KxoM8R5z z0wG-`HTj6^hk^rllMf$v{h;62e1Nf$nTef+k3&Yl0)!O`93C`41Q8Mn1t=0Md@vml o)s8S7AY&j#!Hgl!d~nd^?Al(#(pL5T|924A)78&qol`;+0BU$!1^@s6 diff --git a/data/icons/mate-window-applets/White/minimize/minimize_hovered.png b/data/icons/mate-window-applets/White/minimize/minimize_hovered.png deleted file mode 100644 index ca8e652698a240af17f11970d2dc28b95d3d5241..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 608 zcmeAS@N?(olHy`uVBq!ia0vp^KR}p+4M-lmsLc(e*pj^6U4S$Y{B+)352QE?JR*x3 z7`TN&n2}-D90{Nxdx@v7EBiwh8F4PT=UhHDKq1-8kcblJ{M_8syb>Unfx)>bHL)Z$ zMWH;iBtya7(>EYRFO{8vf$@l^i(^Q|t+#g#`C1eN90CpR{XcahLTW`x+Jn7iv(L_Y zub}d-5NyIwAU?F4{oLbTyYb%c)y};gQQo&dy!>=v7YiQ~yVkBhEY { this.icon_set(event); return false; } ); - this.leave_notify_event.connect( (object,event) => { this.icon_set(event); return false; } ); + this.enter_notify_event.connect( (object,event) => { this.event_set(event); return false; } ); + this.leave_notify_event.connect( (object,event) => { this.event_set(event); return false; } ); + this.button_press_event.connect( (object,event) => { this.event_set(event); return false; } ); + this.button_release_event.connect( (object,event) => { this.event_set(event); return false; } ); } //Helpers @@ -100,89 +81,52 @@ namespace WindowWidgets{ } } - public void icon_set(Gdk.Event *event){ - if(event->get_event_type() == Gdk.EventType.NOTHING || event->get_event_type() == Gdk.EventType.LEAVE_NOTIFY){ - if(_button_type == WindowButtonType.CLOSE){ - if(_window != null && !_window.is_active() && icon_theme.has_icon("close_unfocused")){ - set_icon_by_name("close_unfocused"); - } else if(icon_theme.has_icon("close")){ - set_icon_by_name("close"); - } - } - else if(_button_type == WindowButtonType.MINIMIZE){ - if(_window != null && !_window.is_active() && icon_theme.has_icon("minimize_unfocused")){ - set_icon_by_name("minimize_unfocused"); - } else if(icon_theme.has_icon("minimize")){ - set_icon_by_name("minimize"); - } - } - else if(_button_type == WindowButtonType.MAXIMIZE){ - if(_window != null && _window.is_maximized()){ - if(!_window.is_active() && icon_theme.has_icon("unmaximize_unfocused")){ - set_icon_by_name("unmaximize_unfocused"); - } else if(icon_theme.has_icon("unmaximize")){ - set_icon_by_name("unmaximize"); - } - } - else{ - if(!_window.is_active() && icon_theme.has_icon("maximize_unfocused")){ - set_icon_by_name("maximize_unfocused"); - } else if(icon_theme.has_icon("maximize")){ - set_icon_by_name("maximize"); - } - } - } - } - else if(event->get_event_type() == Gdk.EventType.ENTER_NOTIFY){ - if(_button_type == WindowButtonType.CLOSE){ - if(_window != null && !_window.is_active() && icon_theme.has_icon("close_unfocused_hovered")){ - set_icon_by_name("close_unfocused_hovered"); - } else if(icon_theme.has_icon("close_hovered")){ - set_icon_by_name("close_hovered"); - } - } - else if(_button_type == WindowButtonType.MINIMIZE){ - if(_window != null && !_window.is_active() && icon_theme.has_icon("minimize_unfocused_hovered")){ - set_icon_by_name("minimize_unfocused_hovered"); - } else if(icon_theme.has_icon("minimize_hovered")){ - set_icon_by_name("minimize_hovered"); - } - } - else if(_button_type == WindowButtonType.MAXIMIZE){ - if(_window != null && _window.is_maximized()){ - if(!_window.is_active() && icon_theme.has_icon("unmaximize_unfocused_hovered")){ - set_icon_by_name("unmaximize_unfocused_hovered"); - } else if(icon_theme.has_icon("unmaximize_hovered")){ - set_icon_by_name("unmaximize_hovered"); - } - } - else{ - if(!_window.is_active() && icon_theme.has_icon("maximize_unfocused_hovered")){ - set_icon_by_name("maximize_unfocused_hovered"); - } else if(icon_theme.has_icon("maximize_hovered")){ - set_icon_by_name("maximize_hovered"); - } - } - } - } + public void update(bool reset = false){ + + IconType type; + if(_button_type == WindowButtonType.MINIMIZE) + type = IconType.MINIMIZE; + else if(_button_type == WindowButtonType.MAXIMIZE){ + if(_window != null && _window.is_maximized()) + type = IconType.UNMAXIMIZE; + else + type = IconType.MAXIMIZE; + } else + type = IconType.CLOSE; + - if(_icon != null){ - button_image.set_from_pixbuf(_icon); + IconState state; + if(!reset && _window != null && !_window.is_active()) + state = IconState.UNFOCUSED; + else + state = IconState.FOCUSED; + + + Gdk.Pixbuf? icon = theme.get_icon(type, state, _current_action); + + + if(icon != null){ + icon = icon.scale_simple(_icon_size, _icon_size, Gdk.InterpType.HYPER); + button_image.set_from_pixbuf(icon); } + } - public void theme_set(string value){ - _theme = value; - icon_theme.set_custom_theme(_theme); + private void event_set(Gdk.Event *event){ + if(event->get_event_type() == Gdk.EventType.ENTER_NOTIFY || event->get_event_type() == Gdk.EventType.BUTTON_RELEASE) + _current_action = IconAction.HOVERED; + else if(event->get_event_type() == Gdk.EventType.BUTTON_PRESS) + _current_action = IconAction.PRESSED; + else + _current_action = IconAction.NORMAL; + + this.update(); } - private void set_icon_by_name(string name){ - try{ - _icon = icon_theme.load_icon(name,-1,Gtk.IconLookupFlags.FORCE_SIZE); - _icon = _icon.scale_simple(_icon_size,_icon_size,Gdk.InterpType.HYPER); - } catch (GLib.Error e){ - stdout.printf("Error: %s\n", e.message); - } + public void reload(){ + _current_action = IconAction.NORMAL; + + this.update(true); } } diff --git a/window-buttons-applet/window-buttons-applet.vala b/window-buttons-applet/window-buttons-applet.vala index cc5d8cc..5aa2290 100644 --- a/window-buttons-applet/window-buttons-applet.vala +++ b/window-buttons-applet/window-buttons-applet.vala @@ -29,14 +29,6 @@ namespace WindowButtonsApplet{ public ButtonsApplet(Gtk.Orientation orient){ Object(orientation: orient); - enabled_buttons.close = false; - enabled_buttons.minimize = false; - enabled_buttons.maximize = false; - - this.add(CLOSE); - this.add(MINIMIZE); - this.add(MAXIMIZE); - this.set_homogeneous(true); this.change_layout(); @@ -53,13 +45,18 @@ namespace WindowButtonsApplet{ // Helpers - private void reload_actions(Wnck.Window *window){ + private void reload_actions(){ + if( window == null ){ + CLOSE.set_visible(false); + MINIMIZE.set_visible(false); + MAXIMIZE.set_visible(false); + } else { Wnck.WindowActions actions = window->get_actions(); if(enabled_buttons.close == true){ if((Wnck.WindowActions.CLOSE & actions)>0){ CLOSE.set_visible(true); CLOSE.window = window; - CLOSE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); + CLOSE.reload(); } else CLOSE.set_visible(false); } @@ -67,7 +64,7 @@ namespace WindowButtonsApplet{ if((Wnck.WindowActions.MINIMIZE & actions)>0){ MINIMIZE.set_visible(true); MINIMIZE.window = window; - MINIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); + MINIMIZE.reload(); } else MINIMIZE.set_visible(false); } @@ -75,9 +72,10 @@ namespace WindowButtonsApplet{ if((Wnck.WindowActions.MAXIMIZE & actions)>0){ MAXIMIZE.set_visible(true); MAXIMIZE.window = window; - MAXIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); + MAXIMIZE.reload(); } else MAXIMIZE.set_visible(false); } + } } public void reload(){ @@ -94,17 +92,12 @@ namespace WindowButtonsApplet{ window = get_current_window(); + reload_actions(); + // Watch for changes to new controlled window if(window != null){ window->actions_changed.connect(reload); window->state_changed.connect(reload); - - reload_actions(window); - } - else { - CLOSE.set_visible(false); - MINIMIZE.set_visible(false); - MAXIMIZE.set_visible(false); } // When active window is not the controlled window (because it is unmaximized), @@ -150,43 +143,45 @@ namespace WindowButtonsApplet{ enabled_buttons.maximize = true; } } + + reload_actions(); } public void change_theme(){ - string theme = gsettings.get_string("theme"); + string theme_name = gsettings.get_string("theme"); - if(enabled_buttons.close){ - CLOSE.theme_set(theme); - CLOSE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } + WindowButtonsTheme theme = new WindowButtonsTheme(theme_name); - if(enabled_buttons.minimize){ - MINIMIZE.theme_set(theme); - MINIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } + CLOSE.theme = theme; + if(enabled_buttons.close) + CLOSE.reload(); + + MINIMIZE.theme = theme; + if(enabled_buttons.minimize) + MINIMIZE.reload(); + + MAXIMIZE.theme = theme; + if(enabled_buttons.maximize) + MAXIMIZE.reload(); - if(enabled_buttons.maximize){ - MAXIMIZE.theme_set(theme); - MAXIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } } public void change_size(int size){ int padding = gsettings.get_int("padding"); size -= padding; - if(this.enabled_buttons.close == true){ - CLOSE.icon_size = size; - CLOSE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } - if(this.enabled_buttons.minimize == true){ - MINIMIZE.icon_size = size; - MINIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } - if(this.enabled_buttons.close == true){ - MAXIMIZE.icon_size = size; - MAXIMIZE.icon_set(new Gdk.Event(Gdk.EventType.NOTHING)); - } + CLOSE.icon_size = size; + if(this.enabled_buttons.close == true) + CLOSE.reload(); + + MINIMIZE.icon_size = size; + if(this.enabled_buttons.minimize == true) + MINIMIZE.reload(); + + MAXIMIZE.icon_size = size; + if(this.enabled_buttons.maximize == true) + MAXIMIZE.reload(); + } public void change_orient(int orient){ diff --git a/window-buttons-applet/window-buttons-theme.vala b/window-buttons-applet/window-buttons-theme.vala new file mode 100644 index 0000000..8faa263 --- /dev/null +++ b/window-buttons-applet/window-buttons-theme.vala @@ -0,0 +1,189 @@ +namespace WindowWidgets { + public class WindowButtonsTheme { + + private string _theme_name; + private Gdk.Pixbuf[,,] _pixbufs; + private string[] _extensions; + private string[] _prefixes; + private string[,] _type_names; + private string[,] _state_names; + private string[,] _action_names; + + public WindowButtonsTheme(string name){ + _pixbufs = new Gdk.Pixbuf[ + IconType.TYPES, + IconState.STATES, + IconAction.ACTIONS + ]; + + _theme_name = name; + + _extensions = {"png", "svg"}; + + _prefixes = {null, "button", "icon"}; + + _type_names = { + {"close", null}, + {"minimize", null}, + {"maximize", null}, + {"unmaximize", "restore"} + }; + + _state_names = { + {"focused", ""}, + {"unfocused", null} + }; + + _action_names = { + {"normal", ""}, + {"prelight", null}, + {"pressed", null} + }; + + string[] paths = get_search_paths(); + + load_icons(paths); + + if( _pixbufs[IconType.CLOSE, IconState.FOCUSED, IconAction.NORMAL] == null + || _pixbufs[IconType.MINIMIZE, IconState.FOCUSED, IconAction.NORMAL] == null + || _pixbufs[IconType.MAXIMIZE, IconState.FOCUSED, IconAction.NORMAL] == null ) { + load_fallback_icons(); + } + } + + private string[] get_search_paths(){ + string[] paths = { + Environment.get_home_dir() + "/.icons/mate-window-applets/" + _theme_name, + Environment.get_home_dir() + "/.themes/" + _theme_name + "/metacity-1", + Environment.get_home_dir() + "/.themes/" + _theme_name + "/unity", + "/usr/share/themes/" + _theme_name + "/metacity-1", + "/usr/share/themes/" + _theme_name + "/unity" + }; + string[] result = {}; + foreach(string path in paths){ + if( FileUtils.test(path, FileTest.IS_DIR) ) + result += path; + } + return result; + } + + private void load_icons(string[] paths){ + + for(int type = 0; type < IconType.TYPES; type++){ + for(int state = 0; state < IconState.STATES; state++){ + for(int action = 0; action < IconAction.ACTIONS; action++){ + + var icon_names = get_icon_aliases(type, state, action); + Gdk.Pixbuf icon = find_icon(paths, icon_names); + + if( icon != null ){ + _pixbufs[type, state, action] = icon; + } + + } + } + } + } + + private List get_icon_aliases(int type, int state, int action){ + var aliases = new List (); + for(int i = 0; i < _type_names.length[1]; i++){ + if(_type_names[type,i] == null) + break; + + for(int j = 0; j < _state_names.length[1]; j++){ + if(_state_names[state,j] == null) + break; + + for(int k = 0; k < _action_names.length[1]; k++){ + if(_action_names[action,k] == null) + break; + + string[] parts = {_type_names[type,i]}; + + if(_state_names[state,j] != "") + parts += _state_names[state,j]; + + if(_action_names[action,k] != "") + parts += _action_names[action,k]; + + aliases.append( string.joinv("_", parts) ); + + } + } + } + return aliases; + } + + private Gdk.Pixbuf? find_icon(string[] paths, List icon_names){ + string file_path = find_icon_filepath(paths, icon_names); + if( file_path != null ){ + try { + return new Gdk.Pixbuf.from_file(file_path); + } catch (GLib.Error e){ + stdout.printf("Error: %s\n", e.message); + } + } + return null; + } + + private string? find_icon_filepath(string[] paths, List icon_names){ + foreach(string prefix in _prefixes){ + foreach(string ext in _extensions){ + foreach(string path in paths){ + string result = find_icon_filepath_with(path, ext, prefix, icon_names); + if(result != null) + return result; + } + } + } + return null; + } + + private string? find_icon_filepath_with(string path, string extension, string? prefix, List icon_names){ + foreach(string icon_name in icon_names){ + if(prefix != null) + icon_name = prefix + "_" + icon_name; + + string file_path = path + "/" + icon_name + "." + extension; + if( FileUtils.test(file_path, FileTest.EXISTS) ) + return file_path; + } + return null; + } + + public Gdk.Pixbuf? get_icon(IconType type, IconState state, IconAction action){ + return _pixbufs[type, state, action]; + } + + private void load_fallback_icons(){ + string[] paths = {"/usr/share/pixmaps/mate-window-applets"}; + load_icons(paths); + } + + } + + public enum IconType { + CLOSE = 0, + MINIMIZE, + MAXIMIZE, + UNMAXIMIZE, + + TYPES + } + + public enum IconState { + FOCUSED = 0, + UNFOCUSED, + + STATES + } + + public enum IconAction { + NORMAL = 0, + HOVERED, + PRESSED, + + ACTIONS + } +} \ No newline at end of file