local gears = require("gears")
local awful = require("awful")

clientkeys =
    gears.table.join(
        awful.key(
            {modkey},
            "f",
            function(c)
                c.fullscreen = not c.fullscreen
                c:raise()
            end,
            {description = "toggle fullscreen", group = "client"}
        ),
        awful.key(
            {modkey, "Shift"},
            "c",
            function(c)
                c:kill()
            end,
            {description = "close", group = "client"}
        ),
        awful.key(
            {modkey, "Control"},
            "space",
            function(c)
                if not (awful.screen.focused().selected_tag.layout == awful.layout.suit.floating) and not c.maximized and not c.fullscreen then
                    awful.client.floating.toggle(c)
                    awful.placement.scale(c, {to_percent = 0.65})
                end
            end,
            {description = "toggle floating", group = "client"}
        ),
        awful.key(
            {modkey, "Control"},
            "Return",
            function(c)
                c:swap(awful.client.getmaster())
            end,
            {description = "move to master", group = "client"}
        ),
        awful.key(
            {modkey},
            "o",
            function(c)
                c:move_to_screen()
            end,
            {description = "move to screen", group = "client"}
        ),
        awful.key(
            {modkey},
            "t",
            function(c)
                c.ontop = not c.ontop
            end,
            {description = "toggle keep on top", group = "client"}
        ),
        awful.key(
            {modkey},
            "y",
            function(c)
                c.sticky = not c.sticky
            end,
            {description = "toggle sticky", group = "client"}
        ),
        awful.key(
            {modkey},
            "n",
            function(c)
                -- The client currently has the input focus, so it cannot be
                -- minimized, since minimized clients can't have the focus.
                c.minimized = true
            end,
            {description = "minimize", group = "client"}
        ),
        awful.key(
            {modkey},
            "m",
            function(c)
                c.maximized = not c.maximized
                c:raise()
            end,
            {description = "(un)maximize", group = "client"}
        ),
        awful.key(
            {modkey, "Shift"},
            "m",
            function(c)
                c.maximized_horizontal = not c.maximized_horizontal
                c:raise()
            end,
            {description = "(un)maximize horizontally", group = "client"}
        )
    )

clientbuttons =
    gears.table.join(
        awful.button(
            {},
            1,
            function(c)
                c:emit_signal("request::activate", "mouse_click", {raise = true})
            end
        ),
        awful.button(
            {modkey},
            1,
            function(c)
                if c.focusable then
                    c:emit_signal("request::activate", "mouse_click", {raise = true})
                    awful.mouse.client.move(c)
                end
            end
        ),
        awful.button(
            {modkey},
            3,
            function(c)
                if c.focusable then
                    c:emit_signal("request::activate", "mouse_click", {raise = true})
                    awful.mouse.client.resize(c)
                end
            end
        )
    )
