def spawn(self, lines, additional_args = [ '-p', ''], width = None):
(mouse_x, mouse_y) = get_mouse_location()
if not width:
width = 100 # some default width
width = max(width, 101) # width has to be 100 at least (rofi restriction)
# first, compute the top left corner of the menu
menu_x = min(max(mouse_x - width/2, self.x), self.x + self.panel_width - width)
menu_y = self.y
# then, specify these coordinates relative to the mouse cursor
menu_x -= mouse_x
menu_y -= mouse_y
# compile rofi arguments
cmd = ['rofi', '-dmenu', '-sep' , '\\0' ]
cmd += ['-monitor', '-3' ] # position relative to mouse cursor
cmd += ['-layout', '1' ] # specify top left corner of the menu
cmd += ['-width', str(width) ]
cmd += ['-xoffset', str(menu_x), '-yoffset', str(menu_y) ]
cmd += self.rofi_args
cmd += additional_args
rofi = subprocess.Popen(cmd,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
for i in lines:
rofi.stdin.write(i.encode('utf-8'))
rofi.stdin.write(struct.pack('B', 0))
rofi.stdin.close()
rofi.wait()
评论列表
文章目录