Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
2.11k stars 109 forks source link

feat: Add langugage layout to Actives class #486

Closed enk-it closed 3 months ago

enk-it commented 3 months ago

It allows user to define widget like this:

import PanelButton from "../PanelButton"
import options from "options"
import { sh } from "lib/utils"
const hyprland = await Service.import("hyprland")

const switch_language = () => {
    sh("hyprctl switchxkblayout gaming-keyboard next")
}

const update_icon = (callback_update) => {
    let current_layout = hyprland.active.layout
    callback_update(current_layout.language)
}

const short_name_lang = (name) => {
    if (name.includes("Eng")){
        return 'EN'
    }
    if (name.includes("Rus")){
        return 'RU'
    }
}

export default () => {

    const btn = PanelButton({
        window: "Language",
        class_name: "language",
        child: Widget.Label({
            justification: "center",
            vpack: "center",
        }),
        on_clicked: () => switch_language()
    })

    const update = () => {
        update_icon(
            (result) => {btn.label = short_name_lang(result)}
        )
    }
    return btn.hook(hyprland, update)
}

It allows multilingual users to easily check their current kb layout and switch it from bar изображение