Skip to content

Instantly share code, notes, and snippets.

@SkyyySi
Last active March 14, 2022 21:01
Show Gist options
  • Save SkyyySi/8eef0d21ed3f9560c38573d10c42df4a to your computer and use it in GitHub Desktop.
Save SkyyySi/8eef0d21ed3f9560c38573d10c42df4a to your computer and use it in GitHub Desktop.
Create a sideways wibar in awesome window manager

Create a sideways wibar in awesome wm

Description

The wibar of the awesome window manager is extremely flexible and can do many things that are hard to do with other panels at best, that ususally end up being janky anyway, and sometimes just are not possible outright. One of these things is to move the panel to the side of the screen and have everything behave correctly. In the following, I am going to show you how you can create a panel attactched to the right side of each of your connected screens.

The code

#!/usr/bin/env lua5.3
local awful         = require("awful")
local wibox         = require("wibox")
local gears         = require("gears")
local hotkeys_popup = require("awful.hotkeys_popup")

-- Create a new wibar on the left of the screen.
-- s = the scrren (from `screen.connect_signal...`)
local function sideways_wibar(s)
	local swwb = {}

	if mylauncher then
		swwb.main_menu_button = mylauncher
	else
		swwb.main_menu_content = {
			{ "hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end },
			{ "manual", terminal .. " -e man awesome" },
			{ "edit config", editor_cmd .. " " .. awesome.conffile },
			{ "restart", awesome.restart },
			{ "quit", function() awesome.quit() end },
		}

		swwb.main_menu = awful.menu {
			items = {
				{ "awesome", swwb.main_menu, beautiful.awesome_icon },
				{ "open terminal", terminal or "xterm" }
			}
		}

		swwb.main_menu_launcher = awful.widget.launcher {
			image = beautiful.awesome_icon,
			menu = swwb.main_menu,
		}
	end

	swwb.taglist = awful.widget.taglist {
		screen  = s,
		filter  = awful.widget.taglist.filter.all,
		layout  = {
			layout  = wibox.layout.fixed.vertical
		},
		widget_template = {
			{
				{
					nil,
					{
						id     = "text_role",
						align  = "center",
						valign = "center",
						widget = wibox.widget.textbox,
					},
					nil,
					layout = wibox.layout.align.horizontal,
				},
				margins = 5,
				widget = wibox.container.margin,
			},
			id     = "background_role",
			widget = wibox.container.background,
		},
		buttons = {
			awful.button({ }, 1, function(t) t:view_only() end),
			awful.button({ modkey }, 1, function(t)
				if client.focus then
					client.focus:move_to_tag(t)
				end
			end),
			awful.button({ }, 3, awful.tag.viewtoggle),
			awful.button({ modkey }, 3, function(t)
				if client.focus then
					client.focus:toggle_tag(t)
				end
			end),
			awful.button({ }, 4, function(t) awful.tag.viewprev(t.screen) end),
			awful.button({ }, 5, function(t) awful.tag.viewnext(t.screen) end),
		}
	}

	swwb.layoutbox = awful.widget.layoutbox {
		screen  = s,
		buttons = {
			awful.button({ }, 1, function () awful.layout.inc( 1) end),
			awful.button({ }, 3, function () awful.layout.inc(-1) end),
			awful.button({ }, 4, function () awful.layout.inc(-1) end),
			awful.button({ }, 5, function () awful.layout.inc( 1) end),
		}
	}

	swwb.tasklist = awful.widget.tasklist {
		screen = s,
		filter = awful.widget.tasklist.filter.currenttags,
		layout = {
			layout  = wibox.layout.fixed.vertical
		},
		widget_template = {
			{
				id     = "icon_role",
				widget = wibox.widget.imagebox,
			},
			id     = "background_role",
			widget = wibox.container.background,
		},
		buttons = {
			awful.button({ }, 1, function (c)
				c:activate { context = "tasklist", action = "toggle_minimization" }
			end),
			awful.button({ }, 3, function() awful.menu.client_list { theme = { width = 250 } } end),
			awful.button({ }, 4, function() awful.client.focus.byidx(-1) end),
			awful.button({ }, 5, function() awful.client.focus.byidx( 1) end),
		}
	}

	swwb.clock = wibox.widget {
		nil,
		{
			format = "<b>%H:%M</b>",
			widget = wibox.widget.textclock,
		},
		nil,
		expand = "outside",
		layout = wibox.layout.align.horizontal,
	}

	swwb.systray = wibox.widget {
		horizontal = false,
		widget     = wibox.widget.systray,
	}

	swwb.wibar = awful.wibar {
		position = "left",
		screen = s,
		width = 42,
		widget = {
			{ -- Top
				swwb.main_menu_launcher,
				swwb.taglist,
				layout = wibox.layout.fixed.vertical,
			},
			{ -- Center
				swwb.tasklist,
				layout = wibox.layout.fixed.vertical,
			},
			{ -- Bottom
				swwb.systray,
				swwb.clock,
				swwb.layoutbox,
				layout = wibox.layout.fixed.vertical,
			},
			--expand = "outside",
			layout = wibox.layout.align.vertical,
		}
	}

	return swwb.wibar
end

return sideways_wibar

License

This document is released into the public domain under the Creative Commons Zero (CC0 license) license, while the code snippets within it are licensed under the unlicense. Both licenses can be considered public domain, as-is licenses (this is not legal advice; read the licenses).

Any questions left?

Just leave a comment, I'll try to help!

Tags / SEO / search engine optimization

These are some tags so that people looking for a solution will find this, rather than a dozen disconnected Reddit posts :)

  • awesome
  • awesome wm
  • awesome window manager
  • awesome wm sidebar
  • create sidebar awesome wm
  • move panel to side awesome
  • sideways panel awesome
  • awesome rotate panel
@Kritiqual
Copy link

This is the first time I see someone have a tab's size of 8, lol
Btw, nice gist

@SkyyySi
Copy link
Author

SkyyySi commented Jan 25, 2022

@Kritiqual Well, that's GitHub's fault. I use tabs with a width of 4, and even set that in the GitHub editor - they just don't save that change and always use 8 character wide tabs instead. I guess Microsoft really wants people to use spaces, lol

@pankaj153
Copy link

Add y music best after yt vanced for me but ads comes in this that can be blocked via adblockers very good experimence with that app purpose both you can watch videos either listen song with blocking videos and saving data

@pankaj153
Copy link

Hey pro sir i wanna learn coding independently for myself how can i start as a student

@SkyyySi
Copy link
Author

SkyyySi commented Mar 14, 2022

@pankaj153

Add y music best after yt vanced for me but ads comes in this that can be blocked via adblockers very good experimence with that app purpose both you can watch videos either listen song with blocking videos and saving data

Wrong thread mate ;)

Hey pro sir i wanna learn coding independently for myself how can i start as a student

I learned this by repeatedly trying to make widgets for the Awesome window manager by reading the docs and modifying the code while asking dozens of questions on their Subreddit and Discord. That was my first real experience with programming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment