@@ -12,16 +12,19 @@ local gears = require("gears")
1212local wibox = require (" wibox" )
1313local surface = require (" gears.surface" )
1414local helpers = require (" fishlive.helpers" )
15+ local capi = {
16+ screen = screen
17+ }
1518
1619-- fishlive collage submodule
1720-- fishlive.collage
1821local collage = { _NAME = " fishlive.collage" }
1922
20- function collage .align (align , posx , posy , imgwidth , imgheight )
23+ function collage .align (align , posx , posy , imgwidth , imgheight , screen )
2124 if align == " top-left" then uposx = posx ; uposy = posy
2225 elseif align == " top-right" then uposx = posx - imgwidth ; uposy = posy
23- elseif align == " bottom-left" then uposx = posx + imgwidth ; uposy = posy - imgheight
24- elseif align == " bottom-right" then uposx = posx - imgwidth ; uposy = posy - imgheight
26+ elseif align == " bottom-left" then uposx = screen . geometry . width - posx + imgwidth ; uposy = screen . geometry . height - posy - imgheight
27+ elseif align == " bottom-right" then uposx = screen . geometry . width - posx - imgwidth ; uposy = screen . geometry . height - posy - imgheight
2528 end
2629 return uposx , uposy
2730end
@@ -68,22 +71,25 @@ function collage.calcShadow(imgwidth, imgheight, uposx, uposy)
6871 return width , height , x , y
6972end
7073
71- function collage .placeCollageImage (reqimgwidth , reqimgheight , posx , posy , align , imgsrcs , imgidx , ontop )
74+ function collage .placeCollageImage (s , reqimgwidth , reqimgheight , posx , posy , align , imgsrcs , imgidx , ontop )
7275 local homeDir = os.getenv (" HOME" )
7376 local shadowsrc = homeDir .. " /.config/awesome/fishlive/collage/shadow.png"
7477 local imgsrc = imgsrcs [imgidx ]
7578
7679 local imgwidth , imgheight , imgratio = collage .calcImageRes (imgsrc , reqimgwidth , reqimgheight )
77- local uposx , uposy = collage .align (align , posx , posy , imgwidth , imgheight )
80+ local uposx , uposy = collage .align (align , posx , posy , imgwidth , imgheight , s )
7881 local shwWidth , shwHeight , shwX , shwY = collage .calcShadow (imgwidth , imgheight , uposx , uposy )
7982 local ontop = ontop or false and true
8083
84+ local geom = s .geometry
85+
8186 local imgboxShw = wibox ({
87+ screen = s ,
8288 type = " desktop" ,
8389 width = shwWidth ,
8490 height = shwHeight ,
85- x = shwX ,
86- y = shwY ,
91+ x = geom . x + shwX ,
92+ y = geom . y + shwY ,
8793 visible = true ,
8894 ontop = ontop ,
8995 opacity = 1.00 ,
@@ -103,10 +109,11 @@ function collage.placeCollageImage(reqimgwidth, reqimgheight, posx, posy, align,
103109 }
104110 }
105111 local imgbox = wibox ({
112+ screen = s ,
106113 type = " desktop" ,
107114 width = imgwidth ,
108115 height = imgheight ,
109- x = uposx ,
116+ x = geom . x + uposx ,
110117 y = uposy ,
111118 visible = true ,
112119 ontop = ontop ,
@@ -143,10 +150,11 @@ function collage.placeCollageImage(reqimgwidth, reqimgheight, posx, posy, align,
143150 if imgidx > # imgsrcs then imgidx = 1 end
144151 imgsrc = imgsrcs [imgidx ]
145152 imgwidth , imgheight , imgratio = collage .calcImageRes (imgsrc , reqimgwidth , reqimgheight )
146- uposx , uposy = collage .align (align , posx , posy , imgwidth , imgheight )
153+ uposx , uposy = collage .align (align , posx , posy , imgwidth , imgheight , s )
147154 shwWidth , shwHeight , shwX , shwY = collage .calcShadow (imgwidth , imgheight , uposx , uposy )
148155
149- imgboxShw .x = shwX
156+ imgboxShw .screen = s
157+ imgboxShw .x = geom .x + shwX
150158 imgboxShw .y = shwY
151159 imgboxShw .width = shwWidth
152160 imgboxShw .height = shwHeight
@@ -156,30 +164,42 @@ function collage.placeCollageImage(reqimgwidth, reqimgheight, posx, posy, align,
156164 shwWibox .forced_height = shwHeight
157165 shwWibox .horizontal_fit_policy = " fit"
158166 shwWibox .vertical_fit_policy = " fit"
167+ self .screen = s
159168 self .width = imgwidth
160169 self .height = imgheight
161- self .x = uposx
170+ self .x = geom . x + uposx
162171 self .y = uposy
163172 self :get_children_by_id (" img" )[1 ].image = gears .surface .load_uncached (imgsrc )
164173 end )
165174
166175 return { image = imgbox , shadow = imgboxShw }
167176end
168177
178+ -- function for search and find tag according to bidx or index
179+ local function find_tag_by_ids (id )
180+ for scr in capi .screen do
181+ -- check if bidx is used bidx (for shared tags)
182+ local use_bidx = scr .tags [1 ] and scr .tags [1 ].bidx ~= nil
183+
184+ for _ , tag in ipairs (scr .tags ) do
185+ if (use_bidx and tag .bidx == id ) or (not use_bidx and scr .tags [id ]) then
186+ return tag , scr -- return found tag and its screen
187+ end
188+ end
189+ end
190+ return nil
191+ end
192+
169193-- Tag Collage Changer
170194function collage .registerTagCollage (t )
171- local screen = t .screen
172195 local collage_template = t .collage_template
173196 local imgsources = t .imgsources
174197 local tagids = t .tagids
175198 local imgboxes = nil
176199
177- -- For each screen
178- for scr in screen do
179- -- Go over each tag
180- for t = 1 ,# tagids do
181- local tag = scr .tags [tagids [t ]]
182- if tag == nil then goto continue end
200+ for t = 1 ,# tagids do
201+ local tag = find_tag_by_ids (tagids [t ])
202+ if tag then
183203 tag :connect_signal (" property::selected" , function (tag )
184204 -- if not selected, hide collage
185205 if not tag .selected and imgboxes ~= nil then
@@ -196,6 +216,7 @@ function collage.registerTagCollage(t)
196216 imgboxes = {}
197217 for i = 1 ,# collage_template do
198218 imgboxes [i ] = collage .placeCollageImage (
219+ tag .screen ,
199220 collage_template [i ].max_width or - 1 ,
200221 collage_template [i ].max_height or - 1 ,
201222 collage_template [i ].posx or 0 ,
@@ -215,7 +236,6 @@ function collage.registerTagCollage(t)
215236 end
216237 end
217238 end )
218- :: continue::
219239 end
220240 end
221241end
0 commit comments