Add ags workspaces

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-01 22:59:36 +03:00
parent e5bac20f7d
commit 30d56ebf00
16 changed files with 66 additions and 6 deletions

3
users/configs/ags/config/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
types
bun.lockb

View File

@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"bracketSameLine": true,
"bracketSpacing": true,
"singleQuote": true,
"trailingComma": "all"
}

View File

@@ -0,0 +1,24 @@
{ pkgs ? import <nixpkgs> { }, ... }:
pkgs.stdenv.mkDerivation {
name = "ags-config";
src = ./.;
nativeBuildInputs = with pkgs; [ bun ];
phases = [
"buildPhase"
"installPhase"
];
buildPhase = ''
bun build $src/src/index.ts --outfile=index.js \
--external="file://$src/*" \
--external="gi://*"
'';
installPhase = ''
mkdir -p $out/share
cp index.js $out/share/config.js
'';
}

View File

@@ -0,0 +1,106 @@
/* eslint no-use-before-define: 0 */
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import unicorn from 'eslint-plugin-unicorn';
import prettier from 'eslint-plugin-prettier';
import tsParser from '@typescript-eslint/parser';
export default [
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
'@typescript-eslint': typescriptEslint,
unicorn,
prettier,
},
languageOptions: {
globals: {
...globals.browser,
},
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',
parserOptions: {
project: ['./tsconfig.json'],
},
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
curly: ['error', 'multi-line'],
'eol-last': ['error', 'always'],
semi: ['error', 'always'],
quotes: ['error', 'single'],
'no-await-in-loop': 'warn',
'no-constructor-return': 'error',
'no-duplicate-imports': 'error',
'no-self-compare': 'error',
'no-unreachable-loop': 'error',
'no-trailing-spaces': 'error',
'no-console': 'warn',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/no-misused-promises': ['error', {
checksVoidReturn: false,
}],
'@typescript-eslint/naming-convention': ['error', {
selector: 'default',
format: ['camelCase'],
}, {
selector: 'variableLike',
format: ['camelCase', 'PascalCase'],
}, {
selector: 'memberLike',
format: ['camelCase'],
}, {
selector: 'typeLike',
format: ['PascalCase'],
}, {
selector: 'property',
format: ['snake_case'],
}, {
selector: 'method',
format: ['camelCase'],
}, {
selector: ['enumMember', 'enum'],
format: ['UPPER_CASE'],
}],
'unicorn/empty-brace-spaces': 'off',
'unicorn/expiring-todo-comments': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/filename-case': ['error', {
case: 'camelCase',
}],
'unicorn/numeric-separators-style': 'off',
'unicorn/prevent-abbreviations': 'off',
},
"ignores": ["*.config.js"]
}
];

View File

@@ -0,0 +1,23 @@
{
"name": "ags",
"module": "index.ts",
"type": "module",
"scripts": {
"lint": "eslint ."
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.6.0",
"@types/bun": "^1.1.6",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"eslint": "9.x",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^54.0.0",
"globals": "^15.6.0",
"typescript-eslint": "^7.14.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}

View File

@@ -0,0 +1,17 @@
import gtk from 'gi://Gtk?version=3.0';
import gdk from 'gi://Gdk';
import { range } from 'lib';
import themeInit from 'theme';
import bar from 'widgets/bar/bar';
const forMonitors = (widget: (monitor: number) => gtk.Window) => {
const n = gdk.Display.get_default()?.get_n_monitors() || 1;
return range(n, 0).flatMap(widget);
};
App.config({
style: themeInit(),
windows: [
...forMonitors(bar),
]
});

View File

@@ -0,0 +1,3 @@
export const range = (length: number, start = 1) => {
return Array.from({ length }, (n, i) => i + start);
};

View File

@@ -0,0 +1,25 @@
export default () => {
const css = `${App.configDir}/theme.css`;
const scss = `${App.configDir}/theme.sass`;
let themeExists = true;
try {
Utils.readFile(scss);
Utils.exec(`sassc ${scss} ${css}`);
} catch (error) {
console.error(error);
themeExists = false;
}
Utils.monitorFile(
`${App.configDir}/theme.sass`,
function () {
Utils.exec(`sassc ${scss} ${css}`);
App.resetCss();
App.applyCss(css);
},
);
return themeExists ? css : undefined;
};

View File

@@ -0,0 +1,32 @@
import date from './date/date';
import workspace from './workspace/workspace';
export default (monitor: number) => Widget.Window({
monitor,
class_name: 'bar',
name: `bar${monitor}`,
exclusivity: 'exclusive',
anchor: ['top', 'right', 'left'],
child: Widget.CenterBox({
css: 'min-width: 2px; min-height: 2px; padding-top: 2px; padding-bottom: 2px;',
// eslint-disable-next-line @typescript-eslint/naming-convention
startWidget: Widget.Box({
hexpand: true,
children: [
workspace(),
],
}),
// eslint-disable-next-line @typescript-eslint/naming-convention
centerWidget: Widget.Box({
hpack: 'center',
children: [
date(),
],
}),
// eslint-disable-next-line @typescript-eslint/naming-convention
endWidget: Widget.Box({
hexpand: true,
children: [],
}),
}),
});

View File

@@ -0,0 +1,13 @@
import glib from 'gi://GLib';
const clock = Variable(glib.DateTime.new_now_local(), {
poll: [1000, () => glib.DateTime.new_now_local()]
});
const time = Utils.derive([clock], (c) => c.format('%H:%M - %A, %d %B %Y') || '');
export default () => Widget.Label({
class_name: 'label',
justification: 'center',
label: time.bind(),
});

View File

@@ -0,0 +1,23 @@
import { range } from 'lib';
const hyprland = await Service.import('hyprland');
const dispatch = ws => hyprland.messageAsync(`dispatch workspace ${ws}`);
const workspaceButton = (i: number) => Widget.Label({
class_name: 'button',
attribute: i,
vpack: "center",
setup: self => self.hook(hyprland, () => {
self.toggleClassName('active', hyprland.active.workspace.id === i);
self.toggleClassName('occupied', (hyprland.getWorkspace(i)?.windows || 0) > 0);
}),
});
export default () => Widget.EventBox({
class_name: 'workspace',
onScrollUp: () => dispatch('e-1'),
onScrollDown: () => dispatch('e+1'),
child: Widget.Box({
children: range(10).map(workspaceButton),
}),
});

View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"lib": [
"ES2022"
],
"allowJs": true,
"checkJs": true,
"strict": true,
"noImplicitAny": false,
"baseUrl": "./src",
"typeRoots": [
"./types",
],
"skipLibCheck": true,
}
}