├── .clang-format
├── .codespellrc
├── .github
├── dependabot.yml
└── workflows
│ ├── check-and-build.yml
│ ├── cooldown.yml
│ ├── make-release.yml
│ └── push.yml
├── .gitignore
├── INSTALL.md
├── LICENSE
├── Makefile
├── README.md
├── assets
├── man
│ ├── lidm-config.5
│ └── lidm.1
├── media
│ └── lidm.gif
├── pkg
│ └── aur
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── lidm-bin
│ │ ├── .SRCINFO
│ │ ├── .gitignore
│ │ └── PKGBUILD
│ │ ├── lidm-git
│ │ ├── .SRCINFO
│ │ ├── .gitignore
│ │ └── PKGBUILD
│ │ ├── lidm
│ │ ├── .SRCINFO
│ │ ├── .gitignore
│ │ └── PKGBUILD
│ │ ├── make-srcinfo.sh
│ │ ├── test-makepkg.sh
│ │ └── update-pkgs.sh
└── services
│ ├── README.md
│ ├── dinit
│ ├── openrc
│ ├── runit
│ ├── conf
│ ├── finish
│ └── run
│ ├── s6
│ ├── dependencies.d
│ │ ├── hostname
│ │ └── mount-devfs
│ ├── run
│ └── type
│ └── systemd.service
├── docs
└── CONTRIBUTING.md
├── flake.lock
├── flake.nix
├── include
├── auth.h
├── chvt.h
├── config.h
├── efield.h
├── keys.h
├── sessions.h
├── ui.h
├── users.h
└── util.h
├── src
├── auth.c
├── chvt.c
├── config.c
├── efield.c
├── main.c
├── sessions.c
├── ui.c
├── users.c
└── util.c
└── themes
├── README.md
├── cherry.ini
├── default.ini
├── kanagawa-dragon.ini
├── kanagawa-wave.ini
├── nature.ini
├── nord.ini
├── nothing.ini
├── old-blue.ini
├── screenshots
├── cherry.png
├── default.png
├── kanagawa-dragon.png
├── kanagawa-wave.png
├── nature.png
├── nord.png
├── nothing.png
├── old-blue.png
└── tasteless.png
└── tasteless.ini
/.clang-format:
--------------------------------------------------------------------------------
1 | BasedOnStyle: LLVM
2 | IndentWidth: 2
3 |
--------------------------------------------------------------------------------
/.codespellrc:
--------------------------------------------------------------------------------
1 | [codespell]
2 | skip = ./assets/pkg/aur/*/src,./assets/pkg/aur/*/*/objects
3 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | updates:
4 | - package-ecosystem: "github-actions"
5 | directory: ".github/workflows"
6 | schedule:
7 | interval: "daily"
8 |
--------------------------------------------------------------------------------
/.github/workflows/check-and-build.yml:
--------------------------------------------------------------------------------
1 | name: Check and Build
2 |
3 | on:
4 | workflow_call:
5 | inputs:
6 | set-statuses:
7 | required: false
8 | default: true
9 | type: boolean
10 |
11 | jobs:
12 | spellcheck:
13 | name: Check Grammar
14 | runs-on: ubuntu-24.04
15 |
16 | steps:
17 | - uses: actions/checkout@v4
18 | - uses: awalsh128/cache-apt-pkgs-action@latest
19 | with:
20 | packages: "codespell"
21 | version: 1.0
22 | - run: codespell
23 |
24 | shellcheck:
25 | name: Shell Check
26 | runs-on: ubuntu-24.04
27 |
28 | steps:
29 | - uses: actions/checkout@v4
30 | - uses: awalsh128/cache-apt-pkgs-action@latest
31 | with:
32 | packages: "shellcheck"
33 | version: 1.0
34 | - run: find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck
35 |
36 | clangcheck:
37 | name: Chang Check
38 | runs-on: ubuntu-24.04
39 |
40 | steps:
41 | - uses: actions/checkout@v4
42 | - uses: awalsh128/cache-apt-pkgs-action@latest
43 | with:
44 | packages: "clang-format clang-tidy"
45 | version: 1.0
46 | - run: clang-format -ni src/*.c include/*.h
47 | # TODO: include when the errors/warnings are bearable
48 | #- run: clang-tidy src/*.c include/*.h
49 |
50 | build-linux-amd64:
51 | name: Build for amd64
52 | runs-on: ubuntu-24.04
53 | permissions: write-all
54 | needs: [spellcheck, shellcheck, clangcheck]
55 |
56 | steps:
57 | - uses: actions/checkout@v4
58 | - uses: awalsh128/cache-apt-pkgs-action@latest
59 | with:
60 | packages: "libpam0g-dev"
61 | version: 1.0
62 | - id: build
63 | run: |
64 | make -j$(nproc) 2> /tmp/stderr
65 | cat /tmp/stderr >&2
66 |
67 | HSIZE="$(stat --printf="%s" lidm | numfmt --to=iec-i)B"
68 | WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)"
69 | mv lidm lidm-amd64
70 |
71 | echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT"
72 |
73 | - uses: myrotvorets/set-commit-status-action@master
74 | if: inputs.set-statuses
75 | with:
76 | token: ${{ secrets.GITHUB_TOKEN }}
77 | status: ${{ job.status }}
78 | description: ${{ steps.build.outputs.DESCR }}
79 | context: Build for amd64
80 |
81 | - uses: actions/upload-artifact@v4
82 | with:
83 | name: build-amd64
84 | path: lidm-amd64
85 | retention-days: 1
86 |
87 | build-linux-i386:
88 | name: Build for i386
89 | runs-on: ubuntu-24.04
90 | permissions: write-all
91 | needs: [spellcheck, shellcheck, clangcheck]
92 |
93 | steps:
94 | - uses: actions/checkout@v4
95 | - uses: awalsh128/cache-apt-pkgs-action@latest
96 | with:
97 | packages: "libpam0g-dev gcc-multilib"
98 | version: 1.0
99 | - run: |
100 | sudo dpkg --add-architecture i386
101 | sudo apt-get update -y
102 | sudo apt-get install -y libpam0g-dev:i386
103 |
104 | - id: build
105 | run: |
106 | make -j$(nproc) CFLAGS="-O3 -Wall -m32" 2> /tmp/stderr
107 | cat /tmp/stderr >&2
108 |
109 | HSIZE="$(stat --printf="%s" lidm | numfmt --to=iec-i)B"
110 | WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)"
111 | mv lidm lidm-i386
112 |
113 | echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT"
114 |
115 | - uses: myrotvorets/set-commit-status-action@master
116 | if: inputs.set-statuses
117 | with:
118 | token: ${{ secrets.GITHUB_TOKEN }}
119 | status: ${{ job.status }}
120 | description: ${{ steps.build.outputs.DESCR }}
121 | context: Build for i386
122 |
123 | - uses: actions/upload-artifact@v4
124 | with:
125 | name: build-i386
126 | path: lidm-i386
127 | retention-days: 1
128 |
129 | build-linux-aarch64:
130 | name: Build for aarch64
131 | runs-on: ubuntu-24.04
132 | permissions: write-all
133 | needs: [spellcheck, shellcheck, clangcheck]
134 | steps:
135 | - uses: actions/checkout@v4
136 |
137 | - uses: uraimo/run-on-arch-action@v2
138 | with:
139 | arch: none
140 | distro: none
141 | base_image: '--platform=linux/aarch64 ubuntu:22.04'
142 | githubToken: ${{ github.token }}
143 | install: |
144 | apt-get update && \
145 | apt-get install -y make gcc libpam0g-dev
146 | run: |
147 | make -j$(nproc) 2> /tmp/stderr
148 |
149 | cat /tmp/stderr >&2
150 | mv lidm lidm-aarch64
151 |
152 | - if: inputs.set-statuses
153 | id: status
154 | run: |
155 | HSIZE="$(stat --printf="%s" lidm-aarch64 | numfmt --to=iec-i)B"
156 | WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)"
157 |
158 | echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT"
159 |
160 | - uses: myrotvorets/set-commit-status-action@master
161 | if: inputs.set-statuses
162 | with:
163 | token: ${{ secrets.GITHUB_TOKEN }}
164 | status: ${{ job.status }}
165 | description: ${{ steps.status.outputs.DESCR }}
166 | context: Build for aarch64
167 |
168 | - uses: actions/upload-artifact@v4
169 | with:
170 | name: build-aarch64
171 | path: lidm-aarch64
172 | retention-days: 1
173 |
174 | build-linux-armv7:
175 | name: Build for armv7
176 | runs-on: ubuntu-24.04
177 | permissions: write-all
178 | needs: [spellcheck, shellcheck, clangcheck]
179 | steps:
180 | - uses: actions/checkout@v4
181 |
182 | - uses: uraimo/run-on-arch-action@v2
183 | with:
184 | arch: none
185 | distro: none
186 | base_image: '--platform=linux/arm/v7 ubuntu:22.04'
187 | githubToken: ${{ github.token }}
188 | install: |
189 | apt-get update && \
190 | apt-get install -y make gcc libpam0g-dev
191 | run: |
192 | make -j$(nproc) 2> /tmp/stderr
193 |
194 | cat /tmp/stderr >&2
195 | mv lidm lidm-armv7
196 |
197 | - if: inputs.set-statuses
198 | id: status
199 | run: |
200 | HSIZE="$(stat --printf="%s" lidm-armv7 | numfmt --to=iec-i)B"
201 | WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)"
202 |
203 | echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT"
204 |
205 | - uses: myrotvorets/set-commit-status-action@master
206 | if: inputs.set-statuses
207 | with:
208 | token: ${{ secrets.GITHUB_TOKEN }}
209 | status: ${{ job.status }}
210 | description: ${{ steps.status.outputs.DESCR }}
211 | context: Build for armv7
212 |
213 | - uses: actions/upload-artifact@v4
214 | with:
215 | name: build-armv7
216 | path: lidm-armv7
217 | retention-days: 1
218 |
219 | build-linux-riscv64:
220 | name: Build for riscv64
221 | runs-on: ubuntu-24.04
222 | permissions: write-all
223 | needs: [spellcheck, shellcheck, clangcheck]
224 | steps:
225 | - uses: actions/checkout@v4
226 |
227 | - uses: uraimo/run-on-arch-action@v2
228 | with:
229 | arch: none
230 | distro: none
231 | base_image: '--platform=linux/riscv64 riscv64/ubuntu:22.04'
232 | githubToken: ${{ github.token }}
233 | install: |
234 | apt-get update && \
235 | apt-get install -y make gcc libpam0g-dev
236 | run: |
237 | make -j$(nproc) 2> /tmp/stderr
238 |
239 | cat /tmp/stderr >&2
240 | mv lidm lidm-riscv64
241 |
242 | - if: inputs.set-statuses
243 | id: status
244 | run: |
245 | HSIZE="$(stat --printf="%s" lidm-riscv64 | numfmt --to=iec-i)B"
246 | WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)"
247 |
248 | echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT"
249 |
250 | - uses: myrotvorets/set-commit-status-action@master
251 | if: inputs.set-statuses
252 | with:
253 | token: ${{ secrets.GITHUB_TOKEN }}
254 | status: ${{ job.status }}
255 | description: ${{ steps.status.outputs.DESCR }}
256 | context: Build for riscv64
257 |
258 | - uses: actions/upload-artifact@v4
259 | with:
260 | name: build-riscv64
261 | path: lidm-riscv64
262 | retention-days: 1
263 |
--------------------------------------------------------------------------------
/.github/workflows/cooldown.yml:
--------------------------------------------------------------------------------
1 | name: Issues
2 | on:
3 | issue_comment:
4 | types: [created]
5 | issues:
6 | types: [opened]
7 |
8 | jobs:
9 | cooldown:
10 | name: Cooldown
11 | runs-on: ubuntu-latest
12 | continue-on-error: true
13 | steps:
14 | - name: Cooldown
15 | uses: osy/github-cooldown-action@v1
16 | with:
17 | token: ${{ secrets.GITHUB_TOKEN }}
18 | cooldownMinutes: 15
19 | maxNewIssues: 2
20 | maxNewComments: 15
21 |
--------------------------------------------------------------------------------
/.github/workflows/make-release.yml:
--------------------------------------------------------------------------------
1 | name: Check and Build Release
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | version:
7 | required: true
8 | default: ''
9 | type: string
10 |
11 | jobs:
12 | build:
13 | name: Check and Build
14 | uses: ./.github/workflows/check-and-build.yml
15 | permissions: write-all
16 | with:
17 | set-statuses: false
18 |
19 | release:
20 | name: Make Release v${{ inputs.version }}
21 | runs-on: ubuntu-24.04
22 | permissions: write-all
23 | needs: build
24 | steps:
25 | - uses: actions/download-artifact@v4
26 | with:
27 | path: builds
28 | pattern: build-*
29 | merge-multiple: true
30 |
31 | - uses: ncipollo/release-action@v1
32 | with:
33 | tag: v${{ inputs.version }}
34 | commit: ${{ github.sha }}
35 | artifacts: builds/lidm-*
36 | artifactErrorsFailBuild: true
37 | body: Release notes not generated yet.
38 |
39 | aur-update:
40 | name: Update AUR pkgs
41 | runs-on: ubuntu-24.04
42 | container: archlinux:latest
43 | permissions: write-all
44 | needs: release
45 | steps:
46 | - run: pacman -Sy --noconfirm git github-cli base-devel pacman-contrib
47 |
48 | - uses: actions/checkout@v4
49 |
50 | - run: |
51 | chage -E -1 nobody
52 | passwd -u nobody
53 |
54 | cd "assets/pkg/aur"
55 | chown nobody:nobody . -R
56 | su - -s /bin/bash nobody -c "$PWD/update-pkgs.sh ${{ inputs.version }}"
57 | su - -s /bin/bash nobody -c "$PWD/test-makepkg.sh" # This will also update -git pkgver
58 | chown $UID:$(id -g) . -R
59 |
60 | - run: |
61 | BRANCH=actions/update-aur-${{ inputs.version }}
62 | git config --global --add safe.directory $GITHUB_WORKSPACE
63 | git config user.name "GitHub Actions"
64 | git config user.email "actions@github.com"
65 | git checkout -b $BRANCH
66 | git commit -am "Update AUR pkgs to v${{ inputs.version }}"
67 | git push -u origin $BRANCH
68 | gh pr create --head $BRANCH \
69 | --title "[AUR update]: Bump to ${{ inputs.version }}" \
70 | --body "*This PR was created automatically*"
71 | env:
72 | GH_TOKEN: ${{ github.token }}
73 |
--------------------------------------------------------------------------------
/.github/workflows/push.yml:
--------------------------------------------------------------------------------
1 | name: Push Checks
2 |
3 | on:
4 | push
5 |
6 | jobs:
7 | check-and-build:
8 | name: Check and Build
9 | uses: ./.github/workflows/check-and-build.yml
10 | permissions: write-all
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /lidm
2 | dist/
3 | /compile_commands.json
4 |
5 | .cache/
6 |
7 | # nix build result
8 | result
9 |
--------------------------------------------------------------------------------
/INSTALL.md:
--------------------------------------------------------------------------------
1 | # Index
2 |
3 | - [Index](#index)
4 | - [Installing from Source](#installing-from-source)
5 | - [AUR](#aur)
6 | - [Nix Flake](#nix-flake)
7 |
8 | > [!CAUTION]
9 | > I encourage you to read the manual installation steps to understand what will get installed in your computer by this package.
10 |
11 | # Installing from Source
12 |
13 | Firstly, you'll need to build the package, this also includes man pages, default config, themes and other files you might need.
14 |
15 | To build it you only need to have some basic packages (should come pre-installed in almost all distros): `make`, `gcc` or another `gcc`ish compiler, and libpam headers. If it builds, it surely works anyways.
16 |
17 | ```sh
18 | git clone https://github.com/javalsai/lidm.git
19 | cd lidm
20 | make # 👍
21 | ```
22 |
23 | > [!NOTE]
24 | > There's pre-built binaries on the [releases tab](https://github.com/javalsai/lidm/releases) too.
25 |
26 | Then you can install the files onto your filesystem with:
27 |
28 | ```sh
29 | make install
30 | ```
31 |
32 | And additionally, to install service files (start-up behavior). [more docs](./assets/services/README.md)
33 |
34 | ```sh
35 | # automatically detects your init system
36 | # and install service file (for tty7)
37 | make install-service
38 |
39 | # or if you don't like autodetection
40 | make install-service-systemd # systemd
41 | make install-service-dinit # dinit
42 | make install-service-runit # runit
43 | make install-service-openrc # openrc
44 | make install-service-s6 # s6
45 | ```
46 |
47 | # AUR
48 |
49 | [AUR packages](https://aur.archlinux.org/packages?K=lidm\&SeB=n) will automatically install most files.
50 |
51 | > [!CAUTION]
52 | > [service files](./assets/pkg/aur#services) have to be manually installed by now.
53 |
54 | # Nix Flake
55 |
56 | You can install by doing
57 |
58 | ```sh
59 | nix profile install github:javalsai/lidm
60 | ```
61 |
62 | or try it out without installing by:
63 |
64 | ```sh
65 | nix run github:javalsai/lidm
66 | ```
67 |
68 | > [!CAUTION]
69 | > This doesn't include [service files](./assets/pkg/aur#services) neither
70 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CDIR=src
2 | LDIR=lib
3 | IDIR=include
4 | ODIR=dist
5 |
6 | PREFIX=/usr
7 |
8 | CC?=gcc
9 | CFLAGS?=-O3 -Wall
10 | _CFLAGS=-I$(DIR)
11 | ALLFLAGS=$(CFLAGS) -I$(IDIR)
12 |
13 | LIBS=-lm -lpam -lpam_misc
14 |
15 | _DEPS = util.h ui.h config.h auth.h efield.h keys.h users.h sessions.h chvt.h
16 | DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
17 |
18 | _OBJ = main.o util.o ui.o config.o auth.o efield.o users.o sessions.o chvt.o
19 | OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
20 |
21 | $(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
22 | @mkdir -p $(ODIR)
23 | $(CC) -c -o $@ $< $(ALLFLAGS)
24 |
25 | lidm: $(OBJ)
26 | $(CC) -o $@ $^ $(ALLFLAGS) $(LIBS)
27 |
28 | .PHONY: clean
29 | clean:
30 | rm -f $(ODIR)/*.o lidm
31 |
32 | # Copy lidm to ${DESTDIR}${PREFIX}/bin (/usr/bin)
33 | install: lidm
34 | mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/man/man{1,5}
35 | install -Dm755 ./lidm ${DESTDIR}${PREFIX}/bin/
36 | install -Dm644 ./themes/default.ini ${DESTDIR}/etc/lidm.ini
37 | install -Dm644 ./assets/man/lidm.1 ${DESTDIR}${PREFIX}/share/man/man1/
38 | install -Dm644 ./assets/man/lidm-config.5 ${DESTDIR}${PREFIX}/share/man/man5/
39 |
40 | uninstall:
41 | rm -rf ${DESTDIR}${PREFIX}/bin/lidm ${DESTDIR}/etc/lidm.ini
42 | rm -rf ${DESTDIR}/usr/share/man/man{1/lidm.1,5/lidm-config.5}.gz
43 | rm -rf /etc/systemd/system/lidm.service /etc/dinit.d/lidm /etc/runit/sv/lidm
44 |
45 | install-service:
46 | @if command -v systemctl &> /dev/null; then \
47 | make install-service-systemd; \
48 | elif command -v dinitctl &> /dev/null; then \
49 | make install-service-dinit; \
50 | elif command -v sv &> /dev/null; then \
51 | make install-service-runit; \
52 | elif command -v rc-update &> /dev/null; then \
53 | make install-service-openrc; \
54 | elif command -v s6-service &> /dev/null; then \
55 | make install-service-s6; \
56 | else \
57 | printf '\x1b[1;31m%s\x1b[0m\n' "Unknown init system, skipping service install..."; \
58 | fi
59 |
60 | install-service-systemd:
61 | install -m644 ./assets/services/systemd.service /etc/systemd/system/lidm.service
62 | @printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'systemctl enable lidm'"
63 | install-service-dinit:
64 | install -m644 ./assets/services/dinit /etc/dinit.d/lidm
65 | @printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'dinitctl enable lidm'"
66 | install-service-runit:
67 | rsync -a --no-owner --no-group ./assets/services/runit/. /etc/runit/sv/lidm
68 | @printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'ln -s /etc/runit/sv/lidm /run/runit/service' and 'sv enable lidm'"
69 | install-service-openrc:
70 | install -m755 ./assets/services/openrc /etc/init.d/lidm
71 | @printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'rc-update add lidm'"
72 | install-service-s6:
73 | rsync -a --no-owner --no-group ./assets/services/s6/. /etc/s6/sv/lidm
74 | @printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 's6-service add default lidm' and 's6-db-reload'"
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/javalsai/lidm/blob/master/LICENSE)
2 | [](https://github.com/javalsai/lidm)
3 | [](https://github.com/javalsai/lidm/releases)
4 |
5 | # LiDM
6 |
7 | LiDM is a really light UI portion a unix [login manager](https://en.wikipedia.org/wiki/Login_manager) made in C, highly customizable and held together by hopes and prayers 🙏.
8 |
9 | LiDM is like any [X Display Manager](https://en.wikipedia.org/wiki/X_display_manager) you have seen such as SDDM or GDM but without using X org graphics, instead being a purely [text based interface](https://en.wikipedia.org/wiki/Text-based_user_interface).
10 |
11 | 
12 |
13 | > *shown as in a featured terminal emulator, actual linux console doesn't support as much color and decorations*
14 |
15 | > *however, all colors and strings are fully customizable*
16 |
17 | ## Features
18 |
19 | * Builds **FAST**.
20 | * `a32e4a5`:
21 | * `2.830s`: laptop, -O3, -j2, `AMD E-450 APU with Radeon(tm) HD Graphics`
22 | * `0.172s`: desktop, -O3, -j12, `AMD Ryzen 5 5600G with Radeon Graphics`
23 | * `663427e`:
24 | * `0.085s`: desktop, -O0, `AMD Ryzen 5 5600G with Radeon Graphics`
25 | * `0.009s`: desktop, -O0, CC=tcc, `AMD Ryzen 5 5600G with Radeon Graphics`
26 | * Works everywhere you can get gcc to compile.
27 | * Fast and possibly efficient.
28 | * Fully customizable, from strings, including action keys, to colors (I hope you know ansi escape codes)
29 | * Automatically detects xorg and wayland sessions, plus allowing to launch the default user shell (if enabled in config)
30 | * Starts with many init systems (systemd, dinit, runit, openrc and s6).
31 |
32 | ## WIP
33 |
34 | * Desktop's file `TryExec` key.
35 | * Save last selection.
36 | * Show/hide passwd switch.
37 | * Long sessions, strings, usernames, passwords... they will just overflow or fuck your terminal, I know it and I don't know if I'll fix it.
38 | * UTF characters or any multi-byte character, not yet supported properly, everything treats characters as a single byte, some chars might work or not depending on the context, but it's not designed to.
39 |
40 | # Index
41 |
42 | - [LiDM](#lidm)
43 | - [Features](#features)
44 | - [WIP](#wip)
45 | - [Index](#index)
46 | - [Ideology](#ideology)
47 | - [Usage](#usage)
48 | - [Arguments](#arguments)
49 | - [Program](#program)
50 | - [Requirements](#requirements)
51 | - [Installation](#installation)
52 | - [Configuring](#configuring)
53 | - [Contributing](#contributing)
54 | - [Backstory](#backstory)
55 | - [Contributors](#contributors)
56 |
57 | # Ideology
58 |
59 | We all know that the most important thing in a project is the ideology of the author and the movements he wants to support, so [**#stopchatcontrol**](https://stopchatcontrol.eu).
60 |
61 | [  ](https://stopchatcontrol.eu)
62 |
63 | > *there's also a [change.org post](https://www.change.org/p/stoppt-die-chatkontrolle-grundrechte-gelten-auch-im-netz).*
64 |
65 | # Usage
66 |
67 | ### Arguments
68 |
69 | If a single argument is provided (don't even do `--` or standard parsing...), it passes that argument to `chvt` on startup, used (at least) by most service files.
70 |
71 | ### Program
72 |
73 | On top of pure intuition:
74 |
75 | * You can change focus of session/user/passwd with up/down arrows.
76 | * In case arrow keys do nothing on the focused input (Either is empty text or doesn't have more options), it tries to change session and if there's only one session it changes user.
77 | * Typing anything will allow to put a custom user or shell command too, you can use arrow keys to move.
78 | * ESC and then left/right arrows will force to change the option of the focused input, useful if you're editing the current input and arrow keys just move.
79 | * Editing a predefined option on a user or a shell session, will put you in edit mode preserving the original value, other cases start from scratch.
80 |
81 | # Requirements
82 |
83 | * A computer with unix based system.
84 | * That system should have the resources necessary for this program to make sense (Sessions, users...).
85 | * A compiler (optional, you can compile by hand, but I doubt you want to see the code).
86 | * Make (Also optional, but does things automatically, make sure `gcc` and `mkdir -p` work as expected).
87 | * PAM, used for user authentication, just what `login` or `su` use internally. Don't worry, it's surely pre-installed.
88 |
89 | # Installation
90 |
91 | Check the [installation guide](./INSTALL.md) to use your preferred installation source.
92 |
93 | # Configuring
94 |
95 | Copy any `.ini` file from [`themes/`](./themes/) (`default.ini` will always be updated) to `/etc/lidm.ini` and/or configure it to your liking. Also, don't place empty lines (for now). You can also set `LIDM_CONF` environment variable to specify a config path.
96 |
97 | Configured colors are just gonna be put inside `\x1b[...m`, ofc you can add an 'm' to break this and this can f\*ck up really bad or even make some nice UI effect possible, you should also be able to embed the `\x1b` byte in the config as I won't parse escape codes, I think that the parser is just gonna grab anything in the config file from the space after the `=` (yes, I'ma enforce that space, get good taste if you don't like it) until the newline, you can put any abomination in there. But please, keep in mind this might break easily.
98 |
99 | The default fg style should disable decorators set up in other elements (cursive, underline... it's just adding 20 to the number btw, so if cursive is 4 (iirc), disabling it is 24).
100 |
101 | > [!TIP]
102 | > If you don't like seeing an element, you can change the fg color of it to be the same as the bg, making it invisible.
103 |
104 | # Contributing
105 |
106 | If you want to contribute check the [CONTRIBUTING.md](docs/CONTRIBUTING.md)
107 |
108 | # Backstory
109 |
110 | Summer travelling to visit family with an old laptop that barely supports x86\_64, and ly recently added some avx2 instructions I think (invalid op codes), manually building (any previous commit too) didn't work because of something in the `build.zig` file, so out of boredom I decided to craft up my own simple display manager on the only language this thing can handle... **C** (I hate this and reserve the right for the rust rewrite, actually solid).
111 |
112 | I spedrun it in roughly 3 days and I'm bad af in C, so this is spaghetti code on **another** level. I think it doesn't do almost anything unsafe, I mean, I didn't check allocations and it's capable of reallocating memory until your username uses all memory, crashing the system due to a off-by-one error, but pretty consistent otherwise (probably).
113 |
114 | The name is just ly but changing "y" with "i", that had a reason but forgot it, (maybe the i in *simple*), so I remembered this sh\*tty laptop with a lid, this thing is also a display manager (dm, ly command is also `ly-dm`), so just did lidm due to all that.
115 |
116 | # Contributors
117 |
118 | [](https://github.com/javalsai/lidm/graphs/contributors)
119 |
120 | * KillerTofus, [made the AUR package](https://github.com/javalsai/lidm/pull/2)! Saved me from reading the Arch Wiki 💀.
121 | * DeaDvey, the most awesomest of all, did some pretty HARDCORE gramer checking. (and trolling, he wrote that, 33 commits of just readme changes ffs)
122 | * grialion, made a simple C implementation of `chvt` instead of insecurely relying on `kbd utils`'s command.
123 | * cerealexperiments\_, found a missing newline (had the guts to read the source code, crazy ik)
124 | * ChatGPT, in times of slow laptops where pages take ages to load, a single tab connected to a bunch of burning cloud GPUs feeding corporate hype is all you need to get quick answers for your questions, as long as you know how to filter AI crap ofc.
125 | * [My lack of gf](https://www.instagram.com/reel/C8sa3Gltmtq), can't imagine this project being possible if somebody actually cared about me daily.
126 |
127 | ---
128 |
129 | 🌟 Finally, consider starring this repo or... 🔪
130 |
131 | 
132 |
--------------------------------------------------------------------------------
/assets/man/lidm-config.5:
--------------------------------------------------------------------------------
1 | .\" Manpage for lidm
2 | .\" https://github.com/javalsai/lidm
3 | .TH lidm-config 5
4 |
5 | .SH NAME
6 | lidm-config \- Configuration file syntax for lidm
7 |
8 |
9 | .SH SYNOPSIS
10 | \fB\fI/etc/lidm.ini\fP
11 |
12 |
13 | .SH DESCRIPTION
14 | The \fI/etc/lidm.ini\fP file specifies all the configuration for lidm, including theme colors.
15 |
16 | The config parser is very primitive still, so the file only consists of \fBkey/value\fP pairs separated by \fB' = '\fP (yes, the surrounding spaces are necessary). It will also not warn if the config is invalid.
17 |
18 | You can't escape characters with \fB'\\'\fP, but the program reads until the end of line, so you can put any raw bytes there.
19 |
20 |
21 | .SH KEYS
22 | Similar keys are grouped together to keep this as short as possible.
23 |
24 | .SS Colors
25 | All keys under this section are always wrapped inside ansi sequences (\fB\\x1b[...m\fP).
26 | .TP
27 | \fBcolors.bd, colors.fg, colors.err\fP
28 | Background, foreground and error escape sequences. \fB'fg'\fP is also used as reset sequence, so it must remove effects used in other keys (such as bold, underline...) \fBWITHOUT\fP using the \fB'0'\fP sequence, as that would remove the background color.
29 | .TP
30 | \fBcolors.s_wayland, colors.s_xorg, colors.s_shell\fP
31 | Coloring for sessions of such types (Wayland, X.org, Shells)
32 | .TP
33 | .TP
34 | \fBcolors.e_hostname, colors.e_date, colors.e_box\fP
35 | Coloring for the hostname, date and box elements.
36 | .TP
37 | \fBcolors.e_header\fP
38 | Coloring for heading elements (left column)
39 | .TP
40 | \fBcolors.e_user, colors.e_passwd, colors.e_badpasswd\fP
41 | Coloring for the user element, password and bad padssword.
42 | .TP
43 | \fBcolors.e_key\fP
44 | Coloring for key elements (eg: F1, F2, CTRL...)
45 |
46 | .SS
47 | Single characters used for some elements (can be longer than a character, but it will likely break UI)
48 | .TP
49 | \fBchars.hb, chars.vb\fP
50 | Character for the horizontal bar (hb) and vertical bar (vb).
51 | .TP
52 | \fBchars.ctl, chars.ctr, chars.cbl, chars.cbr\fP
53 | Characters for the corners of the box (ctl = corner top left, cbr = corner bottom right)
54 |
55 | .SS Functions
56 | .TP
57 | \fBfunctions.poweroff, functions.reboot, functions.refresh\fP
58 | Function key to use for such action.
59 |
60 | .SS String
61 | Strings to use for some elements.
62 | .TP
63 | \fBstrings.f_poweroff, strings.f_reboot, strings.f_refresh\fP
64 | Text displayed to name such functions.
65 | .TP
66 | \fBstrings.e_user, strings.e_passwd\fP
67 | Text to display for these element headers.
68 | .TP
69 | \fBstrings.s_wayland, strings.s_xorg, strings.s_shell\fP
70 | Text to display as the header for such sessions.
71 |
72 | .SS Behavior
73 | .TP
74 | \fBbehavior.include_defshell\fP
75 | "true"/"false" (invalid input defaults to false), if true, includes the user default shell as a session to launch
76 | .TP
77 | \fBbehavior.source\fP
78 | Specify paths to source on login, simple KEY=VALUE format with comments (#) or empty'ish lines, quoting or escape sequences not supported yet. It is NOT an array, but you rather assign to it multiple times.
79 | .TP
80 | \fBbehavior.user_source\fP
81 | Same as \fIbehavior.source\fP but relative to user home (if present).
82 |
83 |
84 | .SH "SEE ALSO"
85 | .BR lidm (1)
86 |
--------------------------------------------------------------------------------
/assets/man/lidm.1:
--------------------------------------------------------------------------------
1 | .\" Manpage for lidm
2 | .\" https://github.com/javalsai/lidm
3 | .TH lidm 1
4 |
5 | .SH NAME
6 | lidm \- A text based display manager made in C
7 |
8 |
9 | .SH SYNOPSIS
10 | \fBlidm\fP [TTY]
11 |
12 |
13 | .SH DESCRIPTION
14 | \fBlidm\fP is a text based display manager that supports a lot of configuration. Its focus is to be simple, minimal and easy to compile even on really old hardware, while being as customizable as possible.
15 |
16 |
17 | .SH ARGUMENTS
18 | .TP
19 | \fB[TTY]\fP
20 | TTY to switch to, does not mean that it will run in it.
21 |
22 | .SH ENVIRONMENT
23 | .TP
24 | \fBLIDM_CONF\fP
25 | Specify the config to use other than \fI/etc/lidm.ini\fP
26 |
27 | .SH FILES
28 | .TP
29 | \fI/etc/lidm.ini\fP
30 | Config file, see
31 | .BR lidm-config (5)
32 | for syntax.
33 |
34 |
35 | .SH NOTES
36 | .SS "Service Files"
37 | To configure startup behaviour for your init system, see
38 | .BR https://github.com/javalsai/lidm/tree/master/assets/services
39 | (make sure you're on the same version, the link points to the latest commit, small command arguments might have changed).
40 |
41 |
42 | .SH "SEE ALSO"
43 | .BR lidm-config (5)
44 | .PP
45 | The upstream GitHub repository can be found at
46 | .BR https://github.com/javalsai/lidm
47 |
--------------------------------------------------------------------------------
/assets/media/lidm.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/assets/media/lidm.gif
--------------------------------------------------------------------------------
/assets/pkg/aur/.gitignore:
--------------------------------------------------------------------------------
1 | */*
2 | !*/.gitignore
3 | !*/PKGBUILD
4 | !*/.SRCINFO
5 |
--------------------------------------------------------------------------------
/assets/pkg/aur/README.md:
--------------------------------------------------------------------------------
1 | # AUR Packages
2 |
3 | These files are just for reference, I'll manually edit and publish them, at least until I automate it with github actions (like updating version automatically on a release).
4 |
5 | There are three packages that follow standard conventions:
6 |
7 | * [`lidm`](https://aur.archlinux.org/packages/lidm): Builds latest release (manually updated per release basis)
8 | * [`lidm-bin`](https://aur.archlinux.org/packages/lidm-bin): Fetches latest release binary (compiled by GitHub Actions, also updated per release)
9 | * [`lidm-git`](https://aur.archlinux.org/packages/lidm-git): Fetches latest commit and builds it (should be updated automatically)
10 |
11 | > \[!IMPORTANT]
12 | > None of those packages include the service files. [You have to do this yourself](../../services/README.md).
13 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-bin/.SRCINFO:
--------------------------------------------------------------------------------
1 | pkgbase = lidm-bin
2 | pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary)
3 | pkgver = 0.2.1
4 | pkgrel = 2
5 | url = https://github.com/javalsai/lidm
6 | arch = x86_64
7 | license = GPL
8 | depends = pam
9 | provides = lidm
10 | conflicts = lidm
11 | source = lidm::https://github.com/javalsai/lidm/releases/download/v0.2.1/lidm-amd64
12 | source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/themes/default.ini
13 | source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm.1
14 | source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm-config.5
15 | sha256sums = 4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622
16 | sha256sums = 27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7
17 | sha256sums = a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce
18 | sha256sums = 3adaae60f79dff1cef2b2aba7dcea04196cd49816759ad36afb9f7331ac9c3e4
19 |
20 | pkgname = lidm-bin
21 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-bin/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !PKGBUILD
3 | !.SRCINFO
4 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-bin/PKGBUILD:
--------------------------------------------------------------------------------
1 | # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
2 | # Maintainer: javalsai
3 | pkgname=lidm-bin
4 | pkgver=0.2.1
5 | pkgrel=2
6 | depends=('pam')
7 | pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)"
8 | arch=('x86_64')
9 | url="https://github.com/javalsai/lidm"
10 | license=('GPL')
11 | provides=('lidm')
12 | conflicts=('lidm')
13 | source=(
14 | "lidm::$url/releases/download/v$pkgver/lidm-amd64"
15 | "default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/themes/default.ini"
16 | "lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm.1"
17 | "lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm-config.5"
18 | )
19 | sha256sums=('4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622'
20 | '27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7'
21 | 'a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce'
22 | '3adaae60f79dff1cef2b2aba7dcea04196cd49816759ad36afb9f7331ac9c3e4')
23 |
24 | package() {
25 | install -Dm755 lidm "${pkgdir}/usr/bin/lidm"
26 | install -Dm644 default-theme.ini "${pkgdir}/etc/lidm.ini"
27 | install -Dm644 lidm.1 "${pkgdir}/usr/share/man/man1/lidm.1"
28 | install -Dm644 lidm-config.5 "${pkgdir}/usr/share/man/man5/lidm-config.5"
29 | }
30 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-git/.SRCINFO:
--------------------------------------------------------------------------------
1 | pkgbase = lidm-git
2 | pkgdesc = A fully colorful customizable TUI display manager made in C. (last git commit)
3 | pkgver = 0.1.0.r0.g8071694
4 | pkgrel = 1
5 | url = https://github.com/javalsai/lidm
6 | arch = any
7 | license = GPL
8 | makedepends = git
9 | makedepends = make
10 | makedepends = gcc
11 | depends = pam
12 | provides = lidm
13 | conflicts = lidm
14 | source = lidm::git+https://github.com/javalsai/lidm
15 | sha256sums = SKIP
16 |
17 | pkgname = lidm-git
18 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-git/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !PKGBUILD
3 | !.SRCINFO
4 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm-git/PKGBUILD:
--------------------------------------------------------------------------------
1 | # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
2 | # Maintainer: javalsai
3 | pkgname=lidm-git
4 | pkgver=0.2.1.r0.ge2014f4
5 | pkgrel=1
6 | depends=('pam')
7 | makedepends=('git' 'make' 'gcc')
8 | pkgdesc="A fully colorful customizable TUI display manager made in C. (last git commit)"
9 | arch=('any')
10 | url="https://github.com/javalsai/lidm"
11 | license=('GPL')
12 | provides=('lidm')
13 | conflicts=('lidm')
14 | source=("lidm::git+https://github.com/javalsai/lidm")
15 | sha256sums=('SKIP')
16 |
17 | pkgver() {
18 | cd "lidm"
19 | git describe --long --abbrev=7 --tags | \
20 | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
21 | }
22 |
23 | build() {
24 | cd "lidm"
25 | make CFLAGS="-O3"
26 | }
27 |
28 | package() {
29 | cd "lidm"
30 | make install DESTDIR="${pkgdir}"
31 | }
32 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm/.SRCINFO:
--------------------------------------------------------------------------------
1 | pkgbase = lidm
2 | pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag)
3 | pkgver = 0.2.1
4 | pkgrel = 1
5 | url = https://github.com/javalsai/lidm
6 | arch = any
7 | license = GPL
8 | makedepends = git
9 | makedepends = gcc
10 | depends = pam
11 | source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.2.1.tar.gz
12 | sha256sums = 56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b
13 |
14 | pkgname = lidm
15 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !PKGBUILD
3 | !.SRCINFO
4 |
--------------------------------------------------------------------------------
/assets/pkg/aur/lidm/PKGBUILD:
--------------------------------------------------------------------------------
1 | # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
2 | # Maintainer: javalsai
3 | pkgname=lidm
4 | pkgver=0.2.1
5 | pkgrel=1
6 | depends=('pam')
7 | makedepends=('git' 'gcc')
8 | pkgdesc="A fully colorful customizable TUI display manager made in C. (build latest tag)"
9 | arch=('any')
10 | url="https://github.com/javalsai/lidm"
11 | license=('GPL')
12 | source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz")
13 | sha256sums=('56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b')
14 |
15 | build() {
16 | tar -xzf "tarball.tar.gz"
17 | cd "lidm-$pkgver"
18 |
19 | make CFLAGS="-O3"
20 | }
21 |
22 | package() {
23 | cd "lidm-$pkgver"
24 | make install DESTDIR="${pkgdir}"
25 | }
26 |
--------------------------------------------------------------------------------
/assets/pkg/aur/make-srcinfo.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | MYSELF=$(realpath "$0")
5 | MYDIR=$(dirname "$MYSELF")
6 |
7 | for pkg in "$MYDIR"/*/; do
8 | cd "$pkg"
9 | printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg"
10 | makepkg --printsrcinfo | tee .SRCINFO
11 | echo
12 | done
13 |
--------------------------------------------------------------------------------
/assets/pkg/aur/test-makepkg.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | MYSELF=$(realpath "$0")
5 | MYDIR=$(dirname "$MYSELF")
6 |
7 | for pkg in "$MYDIR"/*/; do
8 | cd "$pkg"
9 | printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg"
10 |
11 | rm -rf ./*.{gz,zst} src pkg
12 | makepkg -f .
13 |
14 | echo
15 | done
16 |
--------------------------------------------------------------------------------
/assets/pkg/aur/update-pkgs.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | MYSELF=$(realpath "$0")
5 | MYDIR=$(dirname "$MYSELF")
6 |
7 | if [ -z "$1" ]; then
8 | printf "\x1b[1;31mERR: No version to update provided\x1b[0m\n" >&2
9 | exit 1;
10 | fi
11 | version="$1"
12 | printf "\x1b[34mINF: Using '%s' version\x1b[0m\n" "$version"
13 |
14 | for pkg in "$MYDIR"/lidm{,-bin}/; do
15 | cd "$pkg"
16 | printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg"
17 | sed -i "s/pkgver=.*/pkgver=$1/" PKGBUILD
18 | sed -i "s/pkgrel=.*/pkgrel=1/" PKGBUILD
19 |
20 | grep 'source = ' <.SRCINFO | awk -F'= |::' '{print $2}' | \
21 | while read -r srcfile; do
22 | printf "\x1b[31mDeleting '%s'\x1b[0m\n" "$srcfile"
23 | rm -f "$srcfile"
24 | done
25 |
26 | updpkgsums
27 | makepkg --printsrcinfo | tee .SRCINFO
28 | echo
29 | done
30 |
--------------------------------------------------------------------------------
/assets/services/README.md:
--------------------------------------------------------------------------------
1 | # Service Files
2 |
3 | This folder contains the files necessary to set up lidm on start up for the supported init systems, all of them are configured for tty7.
4 |
5 | If you don't know what a init system is, you're certainly using `systemd`.
6 |
7 | There's make scripts to automatically copy the service files to the proper locations, you just have to run `make install-service-$INIT`. `make install-service` will attempt to detect the init system in use and install for it.
8 |
9 | The manual steps for installation are:
10 |
11 | ## Systemd
12 |
13 | * Copy `systemd.service` to `/etc/systemd/system/lidm.service`
14 | * To enable it you can run `systemctl enable lidm`
15 |
16 | ## Dinit
17 |
18 | * Copy `dinit` to `/etc/dinit.d/lidm`
19 | * To enable it, run `dinitctl enable lidm`
20 |
21 | ## Runit
22 |
23 | * Copy `runit/` to `/etc/runit/sv/lidm/`
24 | * Add the service with `ln -s /etc/runit/sv/lidm /run/runit/service`
25 | * And to enable it `sv enable lidm`
26 |
27 | ## OpenRC
28 |
29 | * Copy `openrc` to `/etc/init.d/lidm`
30 | * Enable the service with `rc-update add lidm`
31 |
32 | ## S6
33 |
34 | * Copy `s6/` to `/etc/s6/sv/lidm/`
35 | * Add the service with `s6-service add default lidm`
36 | * Reload the database with `s6-db-reload` (you might have to run this every time the service file changes)
37 |
38 | > \[!WARNING]
39 | > Make sure to disable any other service that might run on tty7, such us lightdm or most display managers out there.
40 |
--------------------------------------------------------------------------------
/assets/services/dinit:
--------------------------------------------------------------------------------
1 | type = process
2 | command = /sbin/agetty tty7 linux-c -n -l /bin/lidm -o 7
3 | restart = true
4 | depends-on = login.target
5 | termsignal = HUP
6 | smooth-recovery = true
7 | inittab-id = 7
8 | inittab-line = tty7
9 |
--------------------------------------------------------------------------------
/assets/services/openrc:
--------------------------------------------------------------------------------
1 | #!/usr/bin/openrc-run
2 | description="start agetty on a terminal line"
3 | supervisor=supervise-daemon
4 | port=tty7
5 | respawn_period="${respawn_period:-60}"
6 | term_type="${term_type:-linux}"
7 | command=/sbin/agetty
8 | command_args_foreground="${agetty_options} ${port} ${baud} ${term_type} -nl /bin/lidm -o 7"
9 | pidfile="/run/${RC_SVCNAME}.pid"
10 |
11 | depend() {
12 | after local
13 | keyword -prefix
14 | provide getty
15 | }
16 |
17 | start_pre() {
18 | if [ "$port" = "$RC_SVCNAME" ]; then
19 | eerror "${RC_SVCNAME} cannot be started directly. You must create"
20 | eerror "symbolic links to it for the ports you want to start"
21 | eerror "agetty on and add those to the appropriate runlevels."
22 | return 1
23 | else
24 | export EINFO_QUIET="${quiet:-yes}"
25 | fi
26 | }
27 |
28 | stop_pre()
29 | {
30 | export EINFO_QUIET="${quiet:-yes}"
31 | }
32 |
--------------------------------------------------------------------------------
/assets/services/runit/conf:
--------------------------------------------------------------------------------
1 | BAUD_RATE=38400
2 | TERM_NAME=linux
3 |
4 | TTY=tty7
5 | EXEC_PATH=/bin/lidm
6 |
--------------------------------------------------------------------------------
/assets/services/runit/finish:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | [ -r conf ] && . ./conf
4 |
5 | exec utmpset -w $TTY
6 |
--------------------------------------------------------------------------------
/assets/services/runit/run:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | [ -r conf ] && . ./conf
4 |
5 | if [ -x /sbin/getty -o -x /bin/getty ]; then
6 | # busybox
7 | GETTY=getty
8 | elif [ -x /sbin/agetty -o -x /bin/agetty ]; then
9 | # util-linux
10 | GETTY=agetty
11 | fi
12 |
13 | exec setsid ${GETTY} ${GETTY_ARGS} \
14 | "${TTY}" "${TERM_NAME}" \
15 | -n -l "${EXEC_PATH}" -o 7
16 |
--------------------------------------------------------------------------------
/assets/services/s6/dependencies.d/hostname:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/assets/services/s6/dependencies.d/hostname
--------------------------------------------------------------------------------
/assets/services/s6/dependencies.d/mount-devfs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/assets/services/s6/dependencies.d/mount-devfs
--------------------------------------------------------------------------------
/assets/services/s6/run:
--------------------------------------------------------------------------------
1 | #!/bin/execlineb -P
2 | if { pipeline { s6-rc -ba list } grep -qFx mount-filesystems }
3 | importas -uD "yes" SPAWN SPAWN
4 | importas -sCuD "" ARGS ARGS
5 | importas -sCuD "agetty" GETTY GETTY
6 | if -t { test -e /dev/tty7 }
7 | if -t { test ${SPAWN} = "yes" }
8 | exec agetty -8 tty7 115200 ${ARGS} -nl /bin/lidm -o 7
9 |
--------------------------------------------------------------------------------
/assets/services/s6/type:
--------------------------------------------------------------------------------
1 | longrun
2 |
--------------------------------------------------------------------------------
/assets/services/systemd.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=TUI display manager
3 | After=systemd-user-sessions.service plymouth-quit-wait.service
4 |
5 | [Service]
6 | Type=idle
7 | ExecStart=/usr/bin/lidm 7
8 | StandardError=journal
9 | StandardInput=tty
10 | StandardOutput=tty
11 | TTYPath=/dev/tty7
12 | TTYReset=yes
13 | TTYVHangup=yes
14 |
15 | [Install]
16 | Alias=display-manager.service
17 |
--------------------------------------------------------------------------------
/docs/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are welcome! Here's how you can help:
4 |
5 | - [Contributing code](#code)
6 | - [Reporting issues](#issues)
7 |
8 | ## Code
9 |
10 | For small fixes or incremental improvements simply fork the repo and follow the process below. For larger changes submit an [RFC:](RFC.md)
11 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) the repository and [clone](https://help.github.com/articles/cloning-a-repository/) your fork.
12 |
13 | 2. Start coding!
14 | - Configure clangd LSP by generating `compile_commands.json` (e.g. `bear -- make` or `compiledb make`)
15 | - Implement your feature.
16 | - Check your code works as expected.
17 | - Run the code formatter: `clang-format -i $(git ls-files "*.cpp" "*.h")`
18 |
19 | 3. Commit your changes to a new branch (not `master`, one change per branch) and push it:
20 | - Commit messages should:
21 | - Header line: explain the commit in one line (use the imperative)
22 | - Be descriptive.
23 | - Have a first line with less than *80 characters* and have a second line that is *empty* if you want to add a description.
24 |
25 | 4. Once you are happy with your changes, submit a pull request.
26 | - Open the pull request.
27 | - Add a short description explaining briefly what you've done (or if it's a work-in-progress - what you need to do)
28 |
29 | ## Issues
30 |
31 | 1. Do a quick search on GitHub to check if the issue has already been reported.
32 | 2. [Open an issue](https://github.com//javalsai/lidm/issues/new) and describe the issue you are having - you could include:
33 | - Screenshots.
34 | - Ways to reproduce the issue.
35 | - Your lidm version.
36 | - Your platform (e.g. arch linux or Ubuntu 15.04 x64)
37 |
38 | After reporting you should aim to answer questions or clarifications as this helps pinpoint the cause of the issue.
39 |
40 |
--------------------------------------------------------------------------------
/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "flake-utils": {
4 | "inputs": {
5 | "systems": "systems"
6 | },
7 | "locked": {
8 | "lastModified": 1710146030,
9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
10 | "owner": "numtide",
11 | "repo": "flake-utils",
12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
13 | "type": "github"
14 | },
15 | "original": {
16 | "owner": "numtide",
17 | "repo": "flake-utils",
18 | "type": "github"
19 | }
20 | },
21 | "nixpkgs": {
22 | "locked": {
23 | "lastModified": 1724224976,
24 | "narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=",
25 | "owner": "nixos",
26 | "repo": "nixpkgs",
27 | "rev": "c374d94f1536013ca8e92341b540eba4c22f9c62",
28 | "type": "github"
29 | },
30 | "original": {
31 | "owner": "nixos",
32 | "ref": "nixos-unstable",
33 | "repo": "nixpkgs",
34 | "type": "github"
35 | }
36 | },
37 | "root": {
38 | "inputs": {
39 | "flake-utils": "flake-utils",
40 | "nixpkgs": "nixpkgs"
41 | }
42 | },
43 | "systems": {
44 | "locked": {
45 | "lastModified": 1681028828,
46 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
47 | "owner": "nix-systems",
48 | "repo": "default",
49 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
50 | "type": "github"
51 | },
52 | "original": {
53 | "owner": "nix-systems",
54 | "repo": "default",
55 | "type": "github"
56 | }
57 | }
58 | },
59 | "root": "root",
60 | "version": 7
61 | }
62 |
--------------------------------------------------------------------------------
/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | inputs = {
3 | flake-utils.url = "github:numtide/flake-utils";
4 | nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
5 | };
6 | outputs =
7 | { flake-utils, nixpkgs, ... }:
8 | flake-utils.lib.eachDefaultSystem (
9 | system:
10 | let
11 | pkgs = import nixpkgs { inherit system; };
12 |
13 | name = "lidm";
14 | version = "0.0.2";
15 |
16 | lidm = (
17 | pkgs.stdenv.mkDerivation {
18 | pname = name;
19 | version = version;
20 |
21 | src = ./.;
22 |
23 | nativeBuildInputs = with pkgs; [
24 | gcc
25 | gnumake
26 | linux-pam
27 | ];
28 |
29 | makeFlags = [
30 | "DESTDIR=$(out)"
31 | "PREFIX="
32 | ];
33 |
34 | fixupPhase = ''
35 | rm -rf $out/etc
36 | '';
37 | }
38 | );
39 | in
40 | rec {
41 | defaultApp = flake-utils.lib.mkApp { drv = defaultPackage; };
42 | defaultPackage = lidm;
43 | devShell = pkgs.mkShell { buildInputs = lidm.nativeBuildInputs ++ [ pkgs.clang-tools ]; };
44 | }
45 | );
46 | }
47 |
--------------------------------------------------------------------------------
/include/auth.h:
--------------------------------------------------------------------------------
1 | #ifndef _AUTHH_
2 | #define _AUTHH_
3 |
4 | #include
5 |
6 | #include "config.h"
7 | #include "sessions.h"
8 |
9 | bool launch(char *user, char *passwd, struct session session, void (*cb)(void), struct behavior* behavior);
10 |
11 | #endif
12 |
--------------------------------------------------------------------------------
/include/chvt.h:
--------------------------------------------------------------------------------
1 | #ifndef _CHVTH_
2 | #define _CHVTH_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | /**
11 | * @brief change foreground virtual terminal to `n`
12 | *
13 | * @param n virtual terminal number
14 | * @return int non-negative value on success
15 | */
16 | int chvt(int n);
17 | /**
18 | * @brief change foreground virtual terminal to `str`
19 | *
20 | * @param str virtual terminal number (string)
21 | * @return int non-negative value on success
22 | */
23 | int chvt_str(char *str);
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/include/config.h:
--------------------------------------------------------------------------------
1 | #ifndef _CONFIGH_
2 | #define _CONFIGH_
3 |
4 | #include
5 | #include
6 |
7 | #include "keys.h"
8 | #include "util.h"
9 |
10 | // should be ansi escape codes under \x1b[...m
11 | // if not prepared accordingly, it might break
12 | struct theme_colors {
13 | char *bg;
14 | char *fg;
15 | char *err;
16 | char *s_wayland;
17 | char *s_xorg;
18 | char *s_shell;
19 | char *e_hostname;
20 | char *e_date;
21 | char *e_box;
22 | char *e_header;
23 | char *e_user;
24 | char *e_passwd;
25 | char *e_badpasswd;
26 | char *e_key;
27 | };
28 |
29 | // even if they're multiple bytes long
30 | // they should only take up 1 char size on display
31 | struct theme_chars {
32 | char *hb;
33 | char *vb;
34 |
35 | char *ctl;
36 | char *ctr;
37 | char *cbl;
38 | char *cbr;
39 | };
40 |
41 | struct theme {
42 | struct theme_colors colors;
43 | struct theme_chars chars;
44 | };
45 |
46 | struct functions {
47 | enum keys poweroff;
48 | enum keys reboot;
49 | enum keys refresh;
50 | };
51 |
52 | struct strings {
53 | char *f_poweroff;
54 | char *f_reboot;
55 | char *f_refresh;
56 | char *e_user;
57 | char *e_passwd;
58 | char *s_wayland;
59 | char *s_xorg;
60 | char *s_shell;
61 | };
62 |
63 | struct behavior {
64 | bool include_defshell;
65 | struct Vector source;
66 | struct Vector user_source;
67 | };
68 |
69 | struct config {
70 | struct theme theme;
71 | struct functions functions;
72 | struct strings strings;
73 | struct behavior behavior;
74 | };
75 |
76 | bool line_parser(
77 | FILE *fd, ssize_t *blksize,
78 | u_char (*cb)(char *key,
79 | char *value)); // might use this for parsing .desktop files too
80 | struct config *parse_config(char *path);
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/include/efield.h:
--------------------------------------------------------------------------------
1 | #ifndef _EFIELDH_
2 | #define _EFIELDH_
3 |
4 | #include
5 | #include
6 |
7 | struct editable_field {
8 | u_char length;
9 | u_char pos;
10 | char content[255];
11 | };
12 |
13 | struct editable_field field_new(char *);
14 | void field_trim(struct editable_field *, u_char);
15 | void field_update(struct editable_field *, char *);
16 | bool field_seek(struct editable_field *, char);
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/keys.h:
--------------------------------------------------------------------------------
1 | #ifndef _KEYSH_
2 | #define _KEYSH_
3 |
4 | #include
5 |
6 | enum keys {
7 | ESC,
8 | F1,
9 | F2,
10 | F3,
11 | F4,
12 | F5,
13 | F6,
14 | F7,
15 | F8,
16 | F9,
17 | F10,
18 | F11,
19 | F12,
20 | A_UP,
21 | A_DOWN,
22 | A_RIGHT,
23 | A_LEFT,
24 | N_CENTER,
25 | N_UP,
26 | N_DOWN,
27 | N_RIGHT,
28 | N_LEFT,
29 | INS,
30 | SUPR,
31 | HOME,
32 | END,
33 | PAGE_UP,
34 | PAGE_DOWN,
35 | };
36 |
37 | static const char *const key_names[] = {
38 | [ESC] = "ESC",
39 | [F1] = "F1",
40 | [F2] = "F2",
41 | [F3] = "F3",
42 | [F4] = "F4",
43 | [F5] = "F5",
44 | [F6] = "F6",
45 | [F7] = "F7",
46 | [F8] = "F8",
47 | [F9] = "F9",
48 | [F10] = "F10",
49 | [F11] = "F11",
50 | [F12] = "F12",
51 | [A_UP] = "A_UP",
52 | [A_DOWN] = "A_DOWN",
53 | [A_RIGHT] = "A_RIGHT",
54 | [N_CENTER] = "N_CENTER",
55 | [A_LEFT] = "A_LEFT",
56 | [N_UP] = "N_UP",
57 | [N_DOWN] = "N_DOWN",
58 | [N_RIGHT] = "N_RIGHT",
59 | [N_LEFT] = "N_LEFT",
60 | [INS] = "INS",
61 | [SUPR] = "SUPR",
62 | [HOME] = "HOME",
63 | [END] = "END",
64 | [PAGE_UP] = "PAGE_UP",
65 | [PAGE_DOWN] = "PAGE_DOWN",
66 | };
67 |
68 | struct key_mapping {
69 | enum keys key;
70 | const char *sequences[3];
71 | };
72 |
73 | static const struct key_mapping key_mappings[] = {
74 | {ESC, {"\x1b", NULL}},
75 | {F1, {"\x1bOP", "\x1b[[A", NULL}},
76 | {F2, {"\x1bOQ", "\x1b[[B", NULL}},
77 | {F3, {"\x1bOR", "\x1b[[C", NULL}},
78 | {F4, {"\x1bOS", "\x1b[[D", NULL}},
79 | {F5, {"\x1b[15~", "\x1b[[E", NULL}},
80 | {F6, {"\x1b[17~", NULL}},
81 | {F7, {"\x1b[18~", NULL}},
82 | {F8, {"\x1b[19~", NULL}},
83 | {F9, {"\x1b[20~", NULL}},
84 | {F10, {"\x1b[21~", NULL}},
85 | {F11, {"\x1b[23~", NULL}},
86 | {F12, {"\x1b[24~", NULL}},
87 | {A_UP, {"\x1b[A", NULL}},
88 | {A_DOWN, {"\x1b[B", NULL}},
89 | {A_RIGHT, {"\x1b[C", NULL}},
90 | {A_LEFT, {"\x1b[D", NULL}},
91 | {N_CENTER, {"\x1b[E", NULL}},
92 | {N_UP, {"\x1bOA", NULL}},
93 | {N_DOWN, {"\x1bOB", NULL}},
94 | {N_RIGHT, {"\x1bOC", NULL}},
95 | {N_LEFT, {"\x1bOD", NULL}},
96 | {INS, {"\x1b[2~", NULL}},
97 | {SUPR, {"\x1b[3~", NULL}},
98 | {HOME, {"\x1b[H", NULL}},
99 | {END, {"\x1b[F", NULL}},
100 | {PAGE_UP, {"\x1b[5~", NULL}},
101 | {PAGE_DOWN, {"\x1b[6~", NULL}},
102 | };
103 |
104 | #endif
105 |
--------------------------------------------------------------------------------
/include/sessions.h:
--------------------------------------------------------------------------------
1 | #ifndef _SESSIONSH_
2 | #define _SESSIONSH_
3 |
4 | #include
5 |
6 | #include "util.h"
7 |
8 | enum session_type {
9 | XORG,
10 | WAYLAND,
11 | SHELL,
12 | };
13 |
14 | struct session {
15 | char *name;
16 | char *exec;
17 | char *tryexec;
18 | enum session_type type;
19 | };
20 |
21 | struct Vector get_avaliable_sessions();
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/include/ui.h:
--------------------------------------------------------------------------------
1 | #ifndef _UIH_
2 | #define _UIH_
3 |
4 | #include "config.h"
5 | #include "util.h"
6 |
7 | void setup(struct config);
8 | int load(struct Vector * users, struct Vector * sessions);
9 | void print_err(const char *);
10 | void print_errno(const char *);
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/include/users.h:
--------------------------------------------------------------------------------
1 | #ifndef _USERSH_
2 | #define _USERSH_
3 |
4 | #include
5 |
6 | #include "util.h"
7 |
8 | struct user {
9 | char *shell;
10 | char *username;
11 | char *display_name;
12 | };
13 |
14 | struct Vector get_human_users();
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/include/util.h:
--------------------------------------------------------------------------------
1 | #ifndef _UTILH_
2 | #define _UTILH_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "keys.h"
10 |
11 | enum keys find_keyname(char *);
12 | enum keys find_ansi(char *);
13 | void read_press(u_char *, char *);
14 | void strcln(char **dest, const char *source);
15 |
16 | struct Vector {
17 | uint32_t length;
18 | uint32_t alloc_len;
19 | uint16_t alloc_size;
20 | void** pages;
21 | };
22 |
23 | struct Vector vec_new();
24 | int vec_push(struct Vector*, void* item);
25 | void vec_free(struct Vector*);
26 | void vec_clear(struct Vector*);
27 | void vec_reset(struct Vector*);
28 | void* vec_pop(struct Vector*); // won't free it, nor shrink vec list space
29 | void* vec_get(struct Vector*, size_t index);
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/src/auth.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "auth.h"
12 | #include "config.h"
13 | #include "sessions.h"
14 | #include "ui.h"
15 | #include "unistd.h"
16 | #include "util.h"
17 |
18 | int pam_conversation(int num_msg, const struct pam_message **msg,
19 | struct pam_response **resp, void *appdata_ptr) {
20 | struct pam_response *reply =
21 | (struct pam_response *)malloc(sizeof(struct pam_response) * num_msg);
22 | for (size_t i = 0; i < num_msg; i++) {
23 | reply[i].resp = NULL;
24 | reply[i].resp_retcode = 0;
25 | if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF ||
26 | msg[i]->msg_style == PAM_PROMPT_ECHO_ON) {
27 | char *input = (char *)appdata_ptr;
28 | reply[i].resp = strdup(input);
29 | }
30 | }
31 | *resp = reply;
32 | return PAM_SUCCESS;
33 | }
34 |
35 | #define CHECK_PAM_RET(call) \
36 | ret = (call); \
37 | if (ret != PAM_SUCCESS) { \
38 | pam_end(pamh, ret); \
39 | return NULL; \
40 | }
41 |
42 | void clear_screen() { printf("\x1b[H\x1b[J"); }
43 |
44 | pam_handle_t *get_pamh(char *user, char *passwd) {
45 | pam_handle_t *pamh = NULL;
46 | struct pam_conv pamc = {pam_conversation, (void *)passwd};
47 | int ret;
48 |
49 | CHECK_PAM_RET(pam_start("login", user, &pamc, &pamh))
50 | CHECK_PAM_RET(pam_authenticate(pamh, 0))
51 | CHECK_PAM_RET(pam_acct_mgmt(pamh, 0))
52 | CHECK_PAM_RET(pam_setcred(pamh, PAM_ESTABLISH_CRED))
53 | CHECK_PAM_RET(pam_open_session(pamh, 0))
54 | CHECK_PAM_RET(pam_setcred(pamh, PAM_REINITIALIZE_CRED))
55 |
56 | return pamh;
57 | }
58 | #undef CHECK_PAM_RET
59 |
60 | void *shmalloc(size_t size) {
61 | return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
62 | -1, 0);
63 | }
64 |
65 | void sourceFileTry(char *file) {
66 | FILE *file2source = fopen(file, "r");
67 | if (file2source == NULL)
68 | return;
69 |
70 | char *line = NULL;
71 | size_t len = 0;
72 | ssize_t read;
73 |
74 | while ((read = getline(&line, &len, file2source)) != -1) {
75 | if (read == 0 || (read > 0 && *line == '#'))
76 | continue;
77 | if (line[read - 1] == '\n')
78 | line[read - 1] = '\0';
79 |
80 | /* printf("Retrieved line of length %zu:\n", read); */
81 | /* printf("%s\n", line); */
82 | for (size_t i = 1; i < read; i++) {
83 | if (line[i] == '=') {
84 | /* printf("FOUND '='!\n"); */
85 | line[i] = '\0';
86 | setenv(line, &line[i + 1], 1);
87 | break;
88 | }
89 | }
90 | }
91 |
92 | if (line)
93 | free(line);
94 | fclose(file2source);
95 | }
96 |
97 | void moarEnv(char *user, struct session session, struct passwd *pw,
98 | struct behavior *behavior) {
99 | if (chdir(pw->pw_dir) == -1)
100 | print_errno("can't chdir to user home");
101 |
102 | setenv("HOME", pw->pw_dir, true);
103 | setenv("USER", pw->pw_name, true);
104 | setenv("SHELL", pw->pw_shell, true);
105 | // TERM
106 | setenv("LOGNAME", pw->pw_name, true);
107 | // MAIL?
108 |
109 | // PATH?
110 |
111 | char *xdg_session_type;
112 | if (session.type == SHELL)
113 | xdg_session_type = "tty";
114 | if (session.type == XORG)
115 | xdg_session_type = "x11";
116 | if (session.type == WAYLAND)
117 | xdg_session_type = "wayland";
118 | setenv("XDG_SESSION_TYPE", xdg_session_type, true);
119 |
120 | printf("\n\n\n\n\x1b[1m");
121 | for (size_t i = 0; i < behavior->source.length; i++) {
122 | /* printf("DEBUG(source)!!!! %d %s\n", i, (char*)vec_get(&behavior->source,
123 | * i)); */
124 | sourceFileTry((char *)vec_get(&behavior->source, i));
125 | }
126 | /* printf("\n"); */
127 | if (pw->pw_dir) {
128 | uint home_len = strlen(pw->pw_dir);
129 | for (size_t i = 0; i < behavior->user_source.length; i++) {
130 | char *file2sourcepath = (char *)vec_get(&behavior->user_source, i);
131 | char *newbuf =
132 | malloc(home_len + strlen(file2sourcepath) + 2); // nullbyte and slash
133 | if (newbuf == NULL)
134 | continue; // can't bother
135 | strcpy(newbuf, pw->pw_dir);
136 | newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
137 | strcpy(&newbuf[home_len + 1], file2sourcepath);
138 |
139 | /* printf("DEBUG(user_source)!!!! %d %s\n", i, newbuf); */
140 | sourceFileTry(newbuf);
141 | free(newbuf);
142 | }
143 | }
144 |
145 | /*char *buf;*/
146 | /*size_t bsize = snprintf(NULL, 0, "/run/user/%d", pw->pw_uid) + 1;*/
147 | /*buf = malloc(bsize);*/
148 | /*snprintf(buf, bsize, "/run/user/%d", pw->pw_uid);*/
149 | /*setenv("XDG_RUNTIME_DIR", buf, true);*/
150 | /*setenv("XDG_SESSION_CLASS", "user", true);*/
151 | /*setenv("XDG_SESSION_ID", "1", true);*/
152 | /*setenv("XDG_SESSION_DESKTOP", , true);*/
153 | /*setenv("XDG_SEAT", "seat0", true);*/
154 | }
155 |
156 | bool launch(char *user, char *passwd, struct session session, void (*cb)(void),
157 | struct behavior *behavior) {
158 | struct passwd *pw = getpwnam(user);
159 | if (pw == NULL) {
160 | print_err("could not get user info");
161 | return false;
162 | }
163 |
164 | pam_handle_t *pamh = get_pamh(user, passwd);
165 | if (pamh == NULL) {
166 | print_err("error on pam authentication");
167 | return false;
168 | }
169 |
170 | bool *reach_session = shmalloc(sizeof(bool));
171 | if (reach_session == NULL) {
172 | perror("error allocating shared memory");
173 | return false;
174 | }
175 | *reach_session = false;
176 |
177 | uint pid = fork();
178 | if (pid == 0) { // child
179 | char *TERM = NULL;
180 | char *_GETTERM = getenv("TERM");
181 | if (_GETTERM != NULL)
182 | strcln(&TERM, _GETTERM);
183 | if (clearenv() != 0) {
184 | print_errno("clearenv");
185 | _exit(EXIT_FAILURE);
186 | }
187 |
188 | char **envlist = pam_getenvlist(pamh);
189 | if (envlist == NULL) {
190 | print_errno("pam_getenvlist");
191 | _exit(EXIT_FAILURE);
192 | }
193 | for (size_t i = 0; envlist[i] != NULL; i++) {
194 | putenv(envlist[i]);
195 | }
196 | // FIXME: path hotfix
197 | putenv("PATH=/bin:/usr/bin");
198 | if (TERM != NULL) {
199 | setenv("TERM", TERM, true);
200 | free(TERM);
201 | }
202 |
203 | free(envlist);
204 | moarEnv(user, session, pw, behavior);
205 |
206 | // TODO: chown stdin to user
207 | // does it inherit stdin from parent and
208 | // does parent need to reclaim it after
209 | // this dies?
210 |
211 | if (setgid(pw->pw_gid) == -1) {
212 | print_errno("setgid");
213 | _exit(EXIT_FAILURE);
214 | }
215 | if (initgroups(user, pw->pw_gid) == -1) {
216 | print_errno("initgroups");
217 | _exit(EXIT_FAILURE);
218 | }
219 |
220 | if (setuid(pw->pw_uid) == -1) {
221 | perror("setuid");
222 | _exit(EXIT_FAILURE);
223 | }
224 |
225 | if (cb != NULL)
226 | cb();
227 |
228 | *reach_session = true;
229 |
230 | // TODO: these will be different due to TryExec
231 | // and, Exec/TryExec might contain spaces as args
232 | printf("\x1b[0m");
233 | if (session.type == SHELL) {
234 | clear_screen();
235 | fflush(stdout);
236 | execlp(session.exec, session.exec, NULL);
237 | } else if (session.type == XORG || session.type == WAYLAND) {
238 | clear_screen();
239 | fflush(stdout);
240 | execlp(session.exec, session.exec, NULL);
241 | }
242 | perror("execl error");
243 | fprintf(stderr, "failure calling session\n");
244 | } else {
245 | waitpid(pid, NULL, 0);
246 |
247 | pam_setcred(pamh, PAM_DELETE_CRED);
248 | pam_close_session(pamh, 0);
249 | pam_end(pamh, PAM_SUCCESS);
250 |
251 | if (*reach_session == false) {
252 | return false;
253 | } else
254 | exit(0);
255 | }
256 |
257 | return true;
258 | }
259 |
--------------------------------------------------------------------------------
/src/chvt.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "chvt.h"
7 |
8 | static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
9 | "/dev/console"};
10 |
11 | int chvt_str(char *str) {
12 | char *err;
13 | errno = 0;
14 | long i = strtol(str, &err, 10);
15 | if (errno) {
16 | perror("strol");
17 | return -1;
18 | }
19 | // I'm not gonna elaborate on this....
20 | if (i > INT_MAX || i < INT_MIN || *err)
21 | return -1;
22 |
23 | return chvt((int)i);
24 | }
25 |
26 | int chvt(int n) {
27 | fprintf(stderr, "activating vt %d\n", n);
28 | char c = 0;
29 | for (size_t i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) {
30 | int fd = open(vterms[i], O_RDWR);
31 | if (fd >= 0 && isatty(fd) && ioctl(fd, KDGKBTYPE, &c) == 0 && c < 3) {
32 | if (ioctl(fd, VT_ACTIVATE, n) < 0 || ioctl(fd, VT_WAITACTIVE, n) < 0) {
33 | fprintf(stderr, "Couldn't activate vt %d\n", n);
34 | return -1;
35 | }
36 | return 0;
37 | }
38 | close(fd);
39 | }
40 |
41 | fprintf(stderr, "Couldn't get a file descriptor referring to the console.\n");
42 | return -1;
43 | }
44 |
--------------------------------------------------------------------------------
/src/config.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "config.h"
5 | #include "util.h"
6 |
7 | bool line_parser(FILE *fd, ssize_t *blksize,
8 | u_char (*cb)(char *key, char *value)) {
9 | size_t opt_size = 4096;
10 | if (blksize != NULL)
11 | opt_size = *blksize;
12 |
13 | while (true) {
14 | size_t alloc_size = opt_size;
15 | char *buf = malloc(alloc_size);
16 | if (buf == NULL)
17 | return false;
18 | ssize_t read_size = getline(&buf, &alloc_size, fd);
19 | if (read_size == -1) {
20 | free(buf);
21 | break;
22 | }
23 |
24 | uint read;
25 | char *key = malloc(read_size);
26 | if (key == NULL) {
27 | free(buf);
28 | return false;
29 | }
30 | char *value = malloc(read_size);
31 | if (value == NULL) {
32 | free(buf);
33 | return false;
34 | }
35 | if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, value)) != 0) {
36 | u_char ret = cb(key, value);
37 | if (ret & 0b0100)
38 | free(key);
39 | if (ret & 0b0010)
40 | free(value);
41 | if (ret & 0b1000) {
42 | free(buf);
43 | return false;
44 | }
45 | if (ret & 0b0001) {
46 | free(buf);
47 | break;
48 | }
49 | }
50 | free(buf);
51 | }
52 |
53 | return true;
54 | }
55 |
56 | struct config *__config;
57 | u_char config_line_handler(char *k, char *v) {
58 | if (strcmp(k, "colors.bg") == 0)
59 | __config->theme.colors.bg = v;
60 | else if (strcmp(k, "colors.fg") == 0)
61 | __config->theme.colors.fg = v;
62 | else if (strcmp(k, "colors.err") == 0)
63 | __config->theme.colors.err = v;
64 | else if (strcmp(k, "colors.s_wayland") == 0)
65 | __config->theme.colors.s_wayland = v;
66 | else if (strcmp(k, "colors.s_xorg") == 0)
67 | __config->theme.colors.s_xorg = v;
68 | else if (strcmp(k, "colors.s_shell") == 0)
69 | __config->theme.colors.s_shell = v;
70 | else if (strcmp(k, "colors.e_hostname") == 0)
71 | __config->theme.colors.e_hostname = v;
72 | else if (strcmp(k, "colors.e_date") == 0)
73 | __config->theme.colors.e_date = v;
74 | else if (strcmp(k, "colors.e_box") == 0)
75 | __config->theme.colors.e_box = v;
76 | else if (strcmp(k, "colors.e_header") == 0)
77 | __config->theme.colors.e_header = v;
78 | else if (strcmp(k, "colors.e_user") == 0)
79 | __config->theme.colors.e_user = v;
80 | else if (strcmp(k, "colors.e_passwd") == 0)
81 | __config->theme.colors.e_passwd = v;
82 | else if (strcmp(k, "colors.e_badpasswd") == 0)
83 | __config->theme.colors.e_badpasswd = v;
84 | else if (strcmp(k, "colors.e_key") == 0)
85 | __config->theme.colors.e_key = v;
86 | else if (strcmp(k, "chars.hb") == 0)
87 | __config->theme.chars.hb = v;
88 | else if (strcmp(k, "chars.vb") == 0)
89 | __config->theme.chars.vb = v;
90 | else if (strcmp(k, "chars.ctl") == 0)
91 | __config->theme.chars.ctl = v;
92 | else if (strcmp(k, "chars.ctr") == 0)
93 | __config->theme.chars.ctr = v;
94 | else if (strcmp(k, "chars.cbl") == 0)
95 | __config->theme.chars.cbl = v;
96 | else if (strcmp(k, "chars.cbr") == 0)
97 | __config->theme.chars.cbr = v;
98 | else if (strcmp(k, "functions.poweroff") == 0) {
99 | __config->functions.poweroff = find_keyname(v);
100 | return 0b0110;
101 | }
102 | else if (strcmp(k, "functions.reboot") == 0) {
103 | __config->functions.reboot = find_keyname(v);
104 | return 0b0110;
105 | }
106 | else if (strcmp(k, "functions.refresh") == 0) {
107 | __config->functions.refresh = find_keyname(v);
108 | return 0b0110;
109 | }
110 | else if (strcmp(k, "strings.f_poweroff") == 0)
111 | __config->strings.f_poweroff = v;
112 | else if (strcmp(k, "strings.f_reboot") == 0)
113 | __config->strings.f_reboot = v;
114 | else if (strcmp(k, "strings.f_refresh") == 0)
115 | __config->strings.f_refresh = v;
116 | else if (strcmp(k, "strings.e_user") == 0)
117 | __config->strings.e_user = v;
118 | else if (strcmp(k, "strings.e_passwd") == 0)
119 | __config->strings.e_passwd = v;
120 | else if (strcmp(k, "strings.s_wayland") == 0)
121 | __config->strings.s_wayland = v;
122 | else if (strcmp(k, "strings.s_xorg") == 0)
123 | __config->strings.s_xorg = v;
124 | else if (strcmp(k, "strings.s_shell") == 0)
125 | __config->strings.s_shell = v;
126 | else if (strcmp(k, "behavior.include_defshell") == 0) {
127 | __config->behavior.include_defshell = strcmp(v, "true") == 0;
128 | return 0b0110;
129 | }
130 | else if (strcmp(k, "behavior.source") == 0)
131 | vec_push(&__config->behavior.source, v);
132 | else if (strcmp(k, "behavior.user_source") == 0)
133 | vec_push(&__config->behavior.user_source, v);
134 | else
135 | return 0b1111;
136 |
137 | return 0b100;
138 | }
139 |
140 | struct config *parse_config(char *path) {
141 | struct stat sb;
142 | FILE *fd = fopen(path, "r");
143 | if (fd == NULL || (stat(path, &sb) == -1)) {
144 | perror("fopen");
145 | return NULL;
146 | }
147 |
148 | __config = malloc(sizeof(struct config));
149 | __config->behavior.source = vec_new();
150 | __config->behavior.user_source = vec_new();
151 |
152 | if (__config == NULL)
153 | return NULL;
154 | bool ret = line_parser(fd, (ssize_t *)&sb.st_blksize, config_line_handler);
155 | if (!ret) {
156 | free(__config);
157 | return NULL;
158 | }
159 |
160 | return __config;
161 | }
162 |
--------------------------------------------------------------------------------
/src/efield.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "efield.h"
4 | #include "ui.h"
5 |
6 | struct editable_field field_new(char *content) {
7 | struct editable_field __efield;
8 | if (content != NULL) {
9 | __efield.length = __efield.pos = strlen(content);
10 | memcpy(__efield.content, content, __efield.length);
11 | } else {
12 | field_trim(&__efield, 0);
13 | }
14 | __efield.content[__efield.length] = '\0';
15 | return __efield;
16 | }
17 |
18 | void field_trim(struct editable_field *field, u_char pos) {
19 | field->length = field->pos = pos;
20 | field->content[field->length] = '\0';
21 | }
22 |
23 | void field_update(struct editable_field *field, char *update) {
24 | u_char insert_len = strlen(update);
25 | if (insert_len == 0)
26 | return;
27 |
28 | if (field->pos > field->length)
29 | field->pos = field->length; // WTF
30 | if (insert_len == 1) {
31 | // backspace
32 | if (*update == 127) {
33 | if (field->pos == 0)
34 | return;
35 | if (field->pos < field->length) {
36 | memmove(&field->content[field->pos - 1], &field->content[field->pos],
37 | field->length - field->pos);
38 | }
39 | (field->pos)--;
40 | (field->length)--;
41 | field->content[field->length] = '\0';
42 | return;
43 | }
44 | }
45 |
46 | // append
47 | if (field->length + field->pos >= 255) {
48 | print_err("field too long");
49 | }
50 | if (field->pos < field->length) {
51 | // move with immediate buffer
52 | memmove(&field->content[field->pos + insert_len],
53 | &field->content[field->pos], field->length - field->pos);
54 | }
55 | memcpy(&field->content[field->pos], update, insert_len);
56 |
57 | field->pos += insert_len;
58 | field->length += insert_len;
59 | field->content[field->length] = '\0';
60 | }
61 |
62 | // returns bool depending if it was able to "use" the seek
63 | bool field_seek(struct editable_field *field, char seek) {
64 | if (field->length == 0)
65 | return false;
66 |
67 | if (seek < 0 && -seek > field->pos)
68 | field->pos = 0;
69 | else if (seek > 0 && 255 - field->pos < seek)
70 | field->pos = 255;
71 | else
72 | field->pos += seek;
73 |
74 | if (field->pos > field->length)
75 | field->pos = field->length;
76 |
77 | return true;
78 | }
79 |
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "chvt.h"
8 | #include "config.h"
9 | #include "sessions.h"
10 | #include "ui.h"
11 | #include "users.h"
12 | #include "util.h"
13 |
14 | int main(int argc, char *argv[]) {
15 | if (argc == 2)
16 | chvt_str(argv[1]);
17 |
18 | char *conf_override = getenv("LIDM_CONF");
19 | struct config *config =
20 | parse_config(conf_override == NULL ? "/etc/lidm.ini" : conf_override);
21 | if (config == NULL) {
22 | fprintf(stderr, "error parsing config\n");
23 | return 1;
24 | }
25 | setup(*config);
26 |
27 | struct Vector users = get_human_users();
28 | struct Vector sessions = get_avaliable_sessions();
29 |
30 | int ret = load(&users, &sessions);
31 | if (ret == 0)
32 | execl(argv[0], argv[0], NULL);
33 | }
34 |
--------------------------------------------------------------------------------
/src/sessions.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "sessions.h"
11 | #include "util.h"
12 |
13 | struct source_dir {
14 | enum session_type type;
15 | char *dir;
16 | };
17 | static const struct source_dir sources[] = {
18 | {XORG, "/usr/share/xsessions"},
19 | {WAYLAND, "/usr/share/wayland-sessions"},
20 | };
21 |
22 | static struct session __new_session(enum session_type type, char *name,
23 | const char *exec, const char *tryexec) {
24 | struct session __session;
25 | __session.type = type;
26 | strcln(&__session.name, name);
27 | strcln(&__session.exec, exec);
28 | strcln(&__session.tryexec, tryexec);
29 |
30 | return __session;
31 | }
32 |
33 | static struct Vector *cb_sessions = NULL;
34 |
35 | // NOTE: commented printf's here would be nice to have debug logs if I ever
36 | // implement it
37 | static enum session_type session_type;
38 | static int fn(const char *fpath, const struct stat *sb, int typeflag) {
39 | if (sb == NULL || !S_ISREG(sb->st_mode))
40 | return 0;
41 |
42 | /*printf("gonna open %s\n", fpath);*/
43 | FILE *fd = fopen(fpath, "r");
44 | if (fd == NULL) {
45 | perror("fopen");
46 | fprintf(stderr, "error opening file (r) '%s'\n", fpath);
47 | return 0;
48 | }
49 |
50 | u_char found = 0;
51 | size_t alloc_size = sb->st_blksize;
52 |
53 | char *name_buf = NULL;
54 | char *exec_buf = NULL;
55 | char *tryexec_buf = NULL;
56 | // This should be made a specific function
57 | while (true) {
58 | char *buf = malloc(sb->st_blksize);
59 | ssize_t read_size = getline(&buf, &alloc_size, fd);
60 | if (read_size == -1) {
61 | free(buf);
62 | break;
63 | }
64 |
65 | uint read;
66 | char *key = malloc(read_size + sizeof(char));
67 | char *value = malloc(read_size + sizeof(char));
68 | if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, value)) != 0) {
69 | if (strcmp(key, "Name") == 0) {
70 | found &= 0b001;
71 | name_buf = realloc(value, strlen(value) + sizeof(char));
72 | } else if (strcmp(key, "Exec") == 0) {
73 | found &= 0b010;
74 | exec_buf = realloc(value, strlen(value) + sizeof(char));
75 | } else if (strcmp(key, "TryExec") == 0) {
76 | found &= 0b100;
77 | tryexec_buf = realloc(value, strlen(value) + sizeof(char));
78 | } else {
79 | free(value);
80 | }
81 | }
82 | free(key);
83 | free(buf);
84 | if (found == 0b111) break;
85 | }
86 | /*printf("\nend parsing...\n");*/
87 |
88 | fclose(fd);
89 |
90 | // just add this to the list
91 | if (name_buf != NULL && exec_buf != NULL) {
92 | struct session *session_i = malloc(sizeof (struct session));
93 | *session_i = __new_session(session_type, name_buf, exec_buf,
94 | tryexec_buf == NULL ? "" : tryexec_buf);
95 | vec_push(cb_sessions, session_i);
96 | }
97 |
98 | if (name_buf != NULL)
99 | free(name_buf);
100 | if (exec_buf != NULL)
101 | free(exec_buf);
102 | if (tryexec_buf != NULL)
103 | free(tryexec_buf);
104 |
105 | return 0;
106 | }
107 |
108 | // This code is designed to be run purely single threaded
109 | struct Vector get_avaliable_sessions() {
110 | struct Vector sessions = vec_new();
111 |
112 | cb_sessions = &sessions;
113 | for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {
114 | /*printf("recurring into %s\n", sources[i].dir);*/
115 | session_type = sources[i].type;
116 | ftw(sources[i].dir, &fn, 1);
117 | }
118 | cb_sessions = NULL;
119 |
120 | return sessions;
121 | }
122 |
--------------------------------------------------------------------------------
/src/ui.c:
--------------------------------------------------------------------------------
1 | // i'm sorry
2 | // really sorry
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include "auth.h"
20 | #include "efield.h"
21 | #include "keys.h"
22 | #include "sessions.h"
23 | #include "ui.h"
24 | #include "users.h"
25 | #include "util.h"
26 |
27 | static void print_box();
28 | static void print_footer();
29 | static void restore_all();
30 | static void signal_handler(int);
31 |
32 | const uint boxw = 50;
33 | const uint boxh = 12;
34 |
35 | struct uint_point {
36 | uint x;
37 | uint y;
38 | };
39 |
40 | static void print_session(struct uint_point, struct session, bool);
41 | static void print_user(struct uint_point, struct user, bool);
42 | static void print_passwd(struct uint_point, uint, bool);
43 |
44 | enum input { SESSION, USER, PASSWD };
45 | static u_char inputs_n = 3;
46 |
47 | // ansi resource: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
48 | static struct termios orig_term;
49 | static struct termios term;
50 | static struct winsize window;
51 |
52 | static struct theme theme;
53 | static struct functions functions;
54 | static struct strings strings;
55 | static struct behavior behavior;
56 | void setup(struct config __config) {
57 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &window);
58 |
59 | // 2 padding top and bottom for footer and vertical compensation
60 | // 2 padding left & right to not overflow footer width
61 | if (window.ws_row < boxh + 4 || window.ws_col < boxw + 4) {
62 | fprintf(stderr, "\x1b[1;31mScreen too small\x1b[0m\n");
63 | exit(1);
64 | }
65 |
66 | theme = __config.theme;
67 | functions = __config.functions;
68 | strings = __config.strings;
69 | behavior = __config.behavior;
70 |
71 | tcgetattr(STDOUT_FILENO, &orig_term);
72 | term = orig_term; // save term
73 | // "stty" attrs
74 | term.c_lflag &= ~(ICANON | ECHO);
75 | tcsetattr(STDOUT_FILENO, TCSANOW, &term);
76 |
77 | // save cursor pos, save screen, set color and reset screen
78 | // (applying color to all screen)
79 | printf("\x1b[s\x1b[?47h\x1b[%s;%sm\x1b[2J", theme.colors.bg, theme.colors.fg);
80 |
81 | print_footer();
82 | atexit(restore_all);
83 | signal(SIGINT, signal_handler);
84 | }
85 |
86 | static struct uint_point box_start() {
87 | struct uint_point __start;
88 | __start.x = (window.ws_col - boxw) / 2 + 1;
89 | __start.y = (window.ws_row - boxh) / 2 + 1;
90 | return __start;
91 | }
92 |
93 | static char *fmt_time() {
94 | time_t t = time(NULL);
95 | struct tm tm = *localtime(&t);
96 |
97 | size_t bsize =
98 | snprintf(NULL, 0, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900,
99 | tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec) +
100 | 1;
101 | char *buf = malloc(bsize);
102 | snprintf(buf, bsize, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900,
103 | tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
104 | return buf;
105 | }
106 |
107 | // TODO: handle buffers longer than the buffer (cut str to the end, change
108 | // cursor pos...) should just overlap for now
109 |
110 | // ugh, this represent a field which might have options
111 | // opts is the amount of other options possible (0 will behave as a passwd)
112 | // aaaand (it's an abstract idea, letme think), also holds the status of a
113 | // custom content, like custom launch command or user or smth
114 | struct opt_field {
115 | uint opts;
116 | uint current_opt; // 0 is edit mode btw
117 | struct editable_field efield;
118 | };
119 | void print_ofield(struct opt_field *focused_input);
120 |
121 | static struct opt_field ofield_new(uint opts) {
122 | struct opt_field __field;
123 | __field.opts = opts;
124 | __field.current_opt = 1;
125 | if (opts == 0) {
126 | __field.current_opt = 0;
127 | __field.efield = field_new("");
128 | }
129 | return __field;
130 | }
131 | static void ofield_toedit(struct opt_field *ofield, char *init) {
132 | ofield->current_opt = 0;
133 | ofield->efield = field_new(init);
134 | }
135 | static void ofield_type(struct opt_field *ofield, char *new, char *startstr) {
136 | if (ofield->current_opt != 0)
137 | ofield_toedit(ofield, startstr);
138 | field_update(&ofield->efield, new);
139 | }
140 | // true if it changed anything, single opt fields return false
141 | static bool ofield_opt_seek(struct opt_field *ofield, char seek) {
142 | // TODO: think this
143 | if (ofield->opts == 0 || (ofield->opts == 1 && ofield->current_opt != 0))
144 | return false;
145 |
146 | ofield->current_opt =
147 | 1 + ((ofield->current_opt - 1 + seek + ofield->opts) % ofield->opts);
148 |
149 | print_ofield(ofield);
150 | return true;
151 | }
152 | // true in case it was able to "use" the seek (a empty only editable field
153 | // wouldn't)
154 | static bool ofield_seek(struct opt_field *ofield, char seek) {
155 | if (ofield->current_opt == 0) {
156 | if (field_seek(&ofield->efield, seek)) {
157 | return true;
158 | }
159 | }
160 |
161 | if (ofield->opts == 0)
162 | return false;
163 |
164 | ofield_opt_seek(ofield, seek);
165 |
166 | return true;
167 | }
168 |
169 | static u_char ofield_max_displ_pos(struct opt_field *ofield) {
170 | // TODO: set max cursor pos too
171 | // keep in mind that also have to keep in mind scrolling and ughhh, mentally
172 | // blocked, but this is complex
173 | if (ofield->current_opt == 0)
174 | return ofield->efield.pos;
175 | else
176 | return 0;
177 | }
178 |
179 | enum input focused_input = PASSWD;
180 | struct opt_field of_session;
181 | struct opt_field of_user;
182 | struct opt_field of_passwd;
183 |
184 | struct Vector *gusers;
185 | struct Vector *gsessions;
186 |
187 | // not *that* OF tho
188 | struct opt_field *get_of(enum input from) {
189 | if (from == SESSION)
190 | return &of_session;
191 | if (from == USER)
192 | return &of_user;
193 | if (from == PASSWD)
194 | return &of_passwd;
195 | return NULL;
196 | }
197 |
198 | void ffield_cursor_focus() {
199 | struct uint_point bstart = box_start();
200 | u_char line = bstart.y;
201 | u_char row = bstart.x + 15;
202 |
203 | // rows in here quite bodged
204 | if (focused_input == SESSION) {
205 | line += 5;
206 | row += (of_session.opts > 1) * 2;
207 | } else if (focused_input == USER) {
208 | line += 7;
209 | row += (of_user.opts > 1) * 2;
210 | } else if (focused_input == PASSWD)
211 | line += 9;
212 |
213 | struct opt_field *ofield = get_of(focused_input);
214 | row += ofield->current_opt == 0 ? ofield_max_displ_pos(ofield) : 0;
215 |
216 | printf("\x1b[%d;%dH", line, row);
217 | fflush(stdout);
218 | }
219 |
220 | struct user get_current_user() {
221 | if (of_user.current_opt != 0)
222 | return *(struct user*)vec_get(gusers, of_user.current_opt - 1);
223 | else {
224 | struct user custom_user;
225 | custom_user.shell = "/usr/bin/bash";
226 | custom_user.username = custom_user.display_name = of_user.efield.content;
227 | return custom_user;
228 | }
229 | }
230 |
231 | struct session get_current_session() {
232 | if (of_session.current_opt != 0) {
233 | // this is for the default user shell :P, not the greatest
234 | // implementation but I want to get his done
235 | if (behavior.include_defshell &&
236 | of_session.current_opt == gsessions->length + 1) {
237 | struct session shell_session;
238 | shell_session.type = SHELL;
239 | shell_session.exec = shell_session.name = get_current_user().shell;
240 | return shell_session;
241 | } else
242 | return *(struct session*)vec_get(gsessions, of_session.current_opt - 1);
243 | } else {
244 | struct session custom_session;
245 | custom_session.type = SHELL;
246 | custom_session.name = custom_session.exec = of_session.efield.content;
247 | return custom_session;
248 | }
249 | }
250 |
251 | void print_field(enum input focused_input) {
252 | struct uint_point origin = box_start();
253 |
254 | if (focused_input == PASSWD) {
255 | print_passwd(origin, of_passwd.efield.length, false);
256 | } else if (focused_input == SESSION) {
257 | print_session(origin, get_current_session(), of_session.opts > 1);
258 | } else if (focused_input == USER) {
259 | print_user(origin, get_current_user(), of_user.opts > 1);
260 | print_field(SESSION);
261 | }
262 |
263 | ffield_cursor_focus();
264 | }
265 |
266 | void print_ffield() { print_field(focused_input); }
267 | void print_ofield(struct opt_field *ofield) {
268 | enum input input;
269 | if (ofield == &of_session)
270 | input = SESSION;
271 | else if (ofield == &of_user)
272 | input = USER;
273 | else if (ofield == &of_passwd)
274 | input = PASSWD;
275 | else
276 | return;
277 |
278 | print_field(input);
279 | }
280 |
281 | // true = forward, false = backward
282 | void ffield_move(bool direction) {
283 | if (direction)
284 | focused_input = (focused_input + 1 + inputs_n) % inputs_n;
285 | else
286 | focused_input = (focused_input - 1 + inputs_n) % inputs_n;
287 |
288 | ffield_cursor_focus();
289 | }
290 |
291 | // tf I'm doing
292 | void ffield_change_opt(bool direction) {
293 | struct opt_field *ffield = get_of(focused_input);
294 | if (focused_input == PASSWD)
295 | ffield = &of_session;
296 | if (!ofield_opt_seek(ffield, direction ? 1 : -1)) {
297 | if (focused_input == PASSWD || focused_input == SESSION)
298 | ofield_opt_seek(&of_user, direction ? 1 : -1);
299 | else
300 | ofield_opt_seek(&of_session, direction ? 1 : -1);
301 | }
302 | }
303 | void ffield_change_pos(bool direction) {
304 | struct opt_field *ffield = get_of(focused_input);
305 | if (!ofield_seek(ffield, direction ? 1 : -1))
306 | if (!ofield_opt_seek(&of_session, direction ? 1 : -1))
307 | ofield_opt_seek(&of_user, direction ? 1 : -1);
308 |
309 | ffield_cursor_focus();
310 | }
311 |
312 | void ffield_type(char *text) {
313 | struct opt_field *field = get_of(focused_input);
314 | char *start = "";
315 | if (focused_input == USER && of_user.current_opt != 0)
316 | start = get_current_user().username;
317 | if (focused_input == SESSION && of_session.current_opt != 0 &&
318 | get_current_session().type == SHELL)
319 | start = get_current_session().exec;
320 |
321 | ofield_type(field, text, start);
322 | print_ffield();
323 | }
324 |
325 | int load(struct Vector *users, struct Vector *sessions) {
326 | /// SETUP
327 | gusers = users;
328 | gsessions = sessions;
329 |
330 | // hostnames larger won't render properly
331 | char *hostname = malloc(16);
332 | if (gethostname(hostname, 16) != 0) {
333 | free(hostname);
334 | hostname = "unknown";
335 | } else {
336 | hostname = realloc(hostname, strlen(hostname) + 1);
337 | }
338 |
339 | of_session = ofield_new(sessions->length + behavior.include_defshell);
340 | of_user = ofield_new(users->length);
341 | of_passwd = ofield_new(0);
342 |
343 | /// PRINTING
344 | const struct uint_point boxstart = box_start();
345 |
346 | // printf box
347 | print_box();
348 |
349 | // put hostname
350 | printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
351 | boxstart.x + 12 - (uint)strlen(hostname), theme.colors.e_hostname,
352 | hostname, theme.colors.fg);
353 |
354 | // put date
355 | char *fmtd_time = fmt_time();
356 | printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
357 | boxstart.x + boxw - 3 - (uint)strlen(fmtd_time), theme.colors.e_date,
358 | fmtd_time, theme.colors.fg);
359 |
360 | print_field(SESSION);
361 | print_field(USER);
362 | print_field(PASSWD);
363 | ffield_cursor_focus();
364 |
365 | /// INTERACTIVE
366 | u_char len;
367 | char seq[256];
368 | uint esc = 0;
369 | while (true) {
370 | read_press(&len, seq);
371 | if (*seq == '\x1b') {
372 | enum keys ansi_code = find_ansi(seq);
373 | if (ansi_code != -1) {
374 | if (ansi_code == ESC) {
375 | esc = 2;
376 | } else if (ansi_code == functions.refresh) {
377 | restore_all();
378 | return 0;
379 | } else if (ansi_code == functions.reboot) {
380 | restore_all();
381 | reboot(RB_AUTOBOOT);
382 | exit(0);
383 | } else if (ansi_code == functions.poweroff) {
384 | restore_all();
385 | reboot(RB_POWER_OFF);
386 | exit(0);
387 | } else if (ansi_code == A_UP || ansi_code == A_DOWN) {
388 | ffield_move(ansi_code == A_DOWN);
389 | } else if (ansi_code == A_RIGHT || ansi_code == A_LEFT) {
390 | if (esc)
391 | ffield_change_opt(ansi_code == A_RIGHT);
392 | else
393 | ffield_change_pos(ansi_code == A_RIGHT);
394 | }
395 | }
396 | } else {
397 | if (len == 1 && *seq == '\n') {
398 | if (!launch(get_current_user().username, of_passwd.efield.content,
399 | get_current_session(), &restore_all, &behavior)) {
400 | print_passwd(box_start(), of_passwd.efield.length, true);
401 | ffield_cursor_focus();
402 | }
403 | } else
404 | ffield_type(seq);
405 | }
406 |
407 | if (esc != 0)
408 | esc--;
409 | }
410 | }
411 |
412 | static char *line_cleaner = NULL;
413 | static void clean_line(struct uint_point origin, uint line) {
414 | if (line_cleaner == NULL) {
415 | line_cleaner = malloc((boxw - 2) * sizeof(char) + 1);
416 | memset(line_cleaner, 32, boxw - 2);
417 | line_cleaner[boxw - 2] = 0;
418 | }
419 | printf("\x1b[%d;%dH", origin.y + line, origin.x + 1);
420 | printf("%s", line_cleaner);
421 | }
422 |
423 | // TODO: session_len > 32
424 | static void print_session(struct uint_point origin, struct session session,
425 | bool multiple) {
426 | clean_line(origin, 5);
427 | const char *session_type;
428 | if (session.type == XORG) {
429 | session_type = strings.s_xorg;
430 | } else if (session.type == WAYLAND) {
431 | session_type = strings.s_wayland;
432 | } else {
433 | session_type = strings.s_shell;
434 | }
435 | printf("\r\x1b[%luC\x1b[%sm%s\x1b[%sm",
436 | (ulong)(origin.x + 11 - strlen(session_type)), theme.colors.e_header,
437 | session_type, theme.colors.fg);
438 |
439 | char *session_color;
440 | if (session.type == XORG) {
441 | session_color = theme.colors.s_xorg;
442 | } else if (session.type == WAYLAND) {
443 | session_color = theme.colors.s_wayland;
444 | } else {
445 | session_color = theme.colors.s_shell;
446 | }
447 |
448 | if (multiple) {
449 | printf("\r\x1b[%dC< \x1b[%sm%s\x1b[%sm >", origin.x + 14, session_color,
450 | session.name, theme.colors.fg);
451 | } else {
452 | printf("\r\x1b[%dC\x1b[%sm%s\x1b[%sm", origin.x + 14, session_color,
453 | session.name, theme.colors.fg);
454 | }
455 | }
456 |
457 | // TODO: user_len > 32
458 | static void print_user(struct uint_point origin, struct user user,
459 | bool multiple) {
460 | clean_line(origin, 7);
461 | printf("\r\x1b[%luC\x1b[%sm%s\x1b[%sm",
462 | (ulong)(origin.x + 11 - strlen(strings.e_user)), theme.colors.e_header,
463 | strings.e_user, theme.colors.fg);
464 |
465 | char *user_color = theme.colors.e_user;
466 |
467 | if (multiple) {
468 | printf("\r\x1b[%dC< \x1b[%sm%s\x1b[%sm >", origin.x + 14, user_color,
469 | user.display_name, theme.colors.fg);
470 | } else {
471 | printf("\r\x1b[%dC\x1b[%sm%s\x1b[%sm", origin.x + 14, user_color,
472 | user.display_name, theme.colors.fg);
473 | }
474 | }
475 |
476 | static char passwd_prompt[33];
477 | // TODO: passwd_len > 32
478 | static void print_passwd(struct uint_point origin, uint length, bool err) {
479 | clean_line(origin, 9);
480 | printf("\r\x1b[%luC\x1b[%sm%s\x1b[%sm",
481 | (ulong)(origin.x + 11 - strlen(strings.e_passwd)),
482 | theme.colors.e_header, strings.e_passwd, theme.colors.fg);
483 |
484 | char *pass_color;
485 | if (err)
486 | pass_color = theme.colors.e_badpasswd;
487 | else
488 | pass_color = theme.colors.e_passwd;
489 |
490 | ulong prompt_len = sizeof(passwd_prompt);
491 | ulong actual_len = length > prompt_len ? prompt_len : length;
492 | memset(passwd_prompt, ' ', prompt_len);
493 | memset(passwd_prompt, '*', actual_len);
494 | passwd_prompt[32] = 0;
495 |
496 | printf("\r\x1b[%dC\x1b[%sm", origin.x + 14, pass_color);
497 | printf("%s", passwd_prompt);
498 |
499 | printf("\x1b[%sm", theme.colors.fg);
500 | }
501 |
502 | static void print_empty_row(uint w, uint n, char *edge1, char *edge2) {
503 | for (size_t i = 0; i < n; i++) {
504 | printf("%s\x1b[%dC%s\x1b[%dD\x1b[1B", edge1, w, edge2, w + 2);
505 | }
506 | }
507 |
508 | static void print_row(uint w, uint n, char *edge1, char *edge2, char *filler) {
509 | for (size_t i = 0; i < n; i++) {
510 | printf("%s", edge1);
511 | for (size_t i = 0; i < w; i++) {
512 | printf("%s", filler);
513 | }
514 | printf("%s\x1b[%dD\x1b[1B", edge2, w + 2);
515 | }
516 | }
517 |
518 | static void print_box() {
519 | // TODO: check min sizes
520 | const struct uint_point bstart = box_start();
521 |
522 | printf("\x1b[%d;%dH\x1b[%sm", bstart.y, bstart.x, theme.colors.e_box);
523 | fflush(stdout);
524 | print_row(boxw - 2, 1, theme.chars.ctl, theme.chars.ctr, theme.chars.hb);
525 | print_empty_row(boxw - 2, boxh - 2, theme.chars.vb, theme.chars.vb);
526 | print_row(boxw - 2, 1, theme.chars.cbl, theme.chars.cbr, theme.chars.hb);
527 | printf("\x1b[%sm", theme.colors.fg);
528 | fflush(stdout);
529 | }
530 |
531 | static void print_footer() {
532 | size_t bsize = snprintf(NULL, 0, "%s %s %s %s %s %s", strings.f_poweroff,
533 | key_names[functions.poweroff], strings.f_reboot,
534 | key_names[functions.reboot], strings.f_refresh,
535 | key_names[functions.refresh]);
536 |
537 | uint row = window.ws_row - 1;
538 | uint col = window.ws_col - 2 - bsize;
539 | printf("\x1b[%3$d;%4$dH%8$s \x1b[%1$sm%5$s\x1b[%2$sm %9$s "
540 | "\x1b[%1$sm%6$s\x1b[%2$sm %10$s \x1b[%1$sm%7$s\x1b[%2$sm",
541 | theme.colors.e_key, theme.colors.fg, row, col,
542 | key_names[functions.poweroff], key_names[functions.reboot],
543 | key_names[functions.refresh], strings.f_poweroff, strings.f_reboot,
544 | strings.f_refresh);
545 | fflush(stdout);
546 | }
547 |
548 | void print_err(const char *msg) {
549 | struct uint_point origin = box_start();
550 | fprintf(stderr, "\x1b[%d;%dH%s(%d): %s", origin.y - 1, origin.x, msg, errno,
551 | strerror(errno));
552 | }
553 |
554 | void print_errno(const char *descr) {
555 | struct uint_point origin = box_start();
556 | if (descr == NULL)
557 | fprintf(stderr, "\x1b[%d;%dH\x1b[%smunknown error(%d): %s", origin.y - 1,
558 | origin.x, theme.colors.err, errno, strerror(errno));
559 | else {
560 | fprintf(stderr, "\x1b[%d;%dH\x1b[%sm%s(%d): %s", origin.y - 1, origin.x,
561 | theme.colors.err, descr, errno, strerror(errno));
562 | }
563 | }
564 |
565 | void restore_all() {
566 | // restore cursor pos, restore screen and show cursor
567 | printf("\x1b[u\x1b[?47l\x1b[?25h");
568 | fflush(stdout);
569 | tcsetattr(STDOUT_FILENO, TCSANOW, &orig_term);
570 | }
571 |
572 | void signal_handler(int code) {
573 | restore_all();
574 | exit(code);
575 | }
576 |
--------------------------------------------------------------------------------
/src/users.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "users.h"
9 | #include "util.h"
10 |
11 | static struct user __new_user(struct passwd *p) {
12 | struct user __user;
13 | strcln(&__user.shell, p->pw_shell);
14 | strcln(&__user.username, p->pw_name);
15 | if (p->pw_gecos[0] == '\0')
16 | __user.display_name = __user.username;
17 | else
18 | strcln(&__user.display_name, p->pw_gecos);
19 |
20 | return __user;
21 | }
22 |
23 | // This code is designed to be run purely single threaded
24 | struct Vector get_human_users() {
25 | struct Vector users = vec_new();
26 |
27 | struct passwd *pwd;
28 | while ((pwd = getpwent()) != NULL) {
29 | if (!(pwd->pw_dir && strncmp(pwd->pw_dir, "/home/", 6) == 0))
30 | continue;
31 |
32 | struct user *user_i = malloc(sizeof(struct user));
33 | *user_i = __new_user(pwd);
34 | vec_push(&users, user_i);
35 | }
36 |
37 | return users;
38 | }
39 |
--------------------------------------------------------------------------------
/src/util.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "keys.h"
9 | #include "ui.h"
10 | #include "util.h"
11 |
12 | static int selret_magic();
13 |
14 | void strcln(char **dest, const char *source) {
15 | *dest = malloc(strlen(source) + sizeof(char));
16 | strcpy(*dest, source);
17 | }
18 |
19 | enum keys find_keyname(char *name) {
20 | for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) {
21 | if (strcmp(key_names[i], name) == 0)
22 | return (enum keys)i;
23 | }
24 |
25 | perror("key not found");
26 | exit(1);
27 | }
28 |
29 | enum keys find_ansi(char *seq) {
30 | for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) {
31 | struct key_mapping mapping = key_mappings[i];
32 | for (size_t j = 0; mapping.sequences[j] != NULL; j++) {
33 | if (strcmp(mapping.sequences[j], seq) == 0) {
34 | return (enum keys)i;
35 | }
36 | }
37 | }
38 | return -1;
39 | }
40 |
41 | // https://stackoverflow.com/a/48040042
42 | void read_press(u_char *length, char *out) {
43 | *length = 0;
44 |
45 | while (true) {
46 | if (read(STDIN_FILENO, &out[(*length)++], 1) != 1) {
47 | print_errno("read error");
48 | sleep(3);
49 | exit(1);
50 | }
51 | int selret = selret_magic();
52 | if (selret == -1) {
53 | print_errno("selret error");
54 | } else if (selret != 1) {
55 | out[*length] = '\0';
56 | return;
57 | }
58 | }
59 | }
60 |
61 | static int selret_magic() {
62 | fd_set set;
63 | struct timeval timeout;
64 | FD_ZERO(&set);
65 | FD_SET(STDIN_FILENO, &set);
66 | timeout.tv_sec = 0;
67 | timeout.tv_usec = 0;
68 | return select(1, &set, NULL, NULL, &timeout);
69 | }
70 |
71 |
72 | // Vector shii
73 | struct Vector vec_new() {
74 | struct Vector vec;
75 | vec_reset(&vec);
76 | return vec;
77 | }
78 |
79 | int vec_push(struct Vector* vec, void* item) {
80 | if (vec->length >= vec->alloc_len) {
81 | uint32_t new_size = vec->alloc_len + vec->alloc_size;
82 | void **new_location = realloc(vec->pages, vec->alloc_size);
83 | if (new_location != NULL) {
84 | vec->alloc_size = new_size;
85 | vec->pages = new_location;
86 | } else {
87 | return -1;
88 | }
89 | }
90 |
91 | vec->pages[vec->length] = item;
92 | vec->length++;
93 | return 0;
94 | }
95 |
96 | void vec_free(struct Vector* vec) {
97 | while(vec->length > 0)
98 | free(vec->pages[--vec->length]);
99 |
100 | vec_clear(vec);
101 | }
102 |
103 | void vec_clear(struct Vector* vec) {
104 | free(vec->pages);
105 | vec_reset(vec);
106 | }
107 |
108 | void vec_reset(struct Vector* vec) {
109 | vec->length = 0;
110 | vec->alloc_len = 0;
111 | vec->alloc_size = 4096; // 4KiB page size?
112 | vec->pages = NULL;
113 | }
114 |
115 | void* vec_pop(struct Vector* vec) {
116 | if (vec->length == 0)
117 | return NULL;
118 |
119 | return vec->pages[--vec->length];
120 | }
121 |
122 | void* vec_get(struct Vector* vec, size_t index) {
123 | if (index >= vec->length)
124 | return NULL;
125 |
126 | return vec->pages[index];
127 | }
128 |
--------------------------------------------------------------------------------
/themes/README.md:
--------------------------------------------------------------------------------
1 | # Themes
2 |
3 | ## cherry.ini
4 |
5 | 
6 |
7 | ## default.ini
8 |
9 | 
10 |
11 | ## kanagawa-dragon.ini
12 |
13 | 
14 |
15 | ## kanagawa-wave.ini
16 |
17 | 
18 |
19 | ## nature.ini
20 |
21 | 
22 |
23 | ## nord.ini
24 |
25 | 
26 |
27 | ## old-blue.ini
28 |
29 | 
30 |
31 | ## nothing.ini
32 |
33 | 
34 |
35 | ## tasteless.ini
36 |
37 | 
38 |
--------------------------------------------------------------------------------
/themes/cherry.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;77;33;55
2 | colors.fg = 22;3;24;38;2;245;245;245
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 32
7 | colors.e_hostname = 1;23;38;5;197
8 | colors.e_date = 31
9 | colors.e_box = 31
10 | colors.e_header = 1;4;38;5;204
11 | colors.e_user = 38;5;51
12 | colors.e_passwd = 4;2;38;5;203
13 | colors.e_badpasswd = 4;31
14 | colors.e_key = 1;23;38;5;197
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/default.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;38;28;28
2 | colors.fg = 22;24;38;2;245;245;245
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 38;2;34;140;34
7 | colors.e_hostname = 38;2;255;64;64
8 | colors.e_date = 38;2;144;144;144
9 | colors.e_box = 38;2;122;122;122
10 | colors.e_header = 4;38;2;0;255;0
11 | colors.e_user = 36
12 | colors.e_passwd = 4;38;2;245;245;205
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 38;2;255;174;66
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/kanagawa-dragon.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;24;22;22
2 | colors.fg = 22;24;38;2;185;185;185
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 38;2;34;140;34
7 | colors.e_hostname = 38;2;208;189;156
8 | colors.e_date = 38;2;144;144;144
9 | colors.e_box = 38;2;122;122;122
10 | colors.e_header = 4;38;2;126;146;178
11 | colors.e_user = 38;2;148;89;84
12 | colors.e_passwd = 4;38;2;245;245;205
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 38;2;255;174;66
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/kanagawa-wave.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;28;28;36
2 | colors.fg = 22;24;38;2;168;168;168
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 38;2;34;140;34
7 | colors.e_hostname = 38;2;196;165;112
8 | colors.e_date = 38;2;144;144;144
9 | colors.e_box = 38;2;122;122;122
10 | colors.e_header = 4;38;2;114;133;162
11 | colors.e_user = 38;2;211;137;88
12 | colors.e_passwd = 4;38;2;245;245;205
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 38;2;255;174;66
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/nature.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;15;22;15
2 | colors.fg = 22;23;24;38;2;245;245;245
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 32
7 | colors.e_hostname = 38;5;28
8 | colors.e_date = 32
9 | colors.e_box = 32
10 | colors.e_header = 1;4;32
11 | colors.e_user = 38;5;51
12 | colors.e_passwd = 4;2;38;5;83
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 32
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/nord.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;19;19;22
2 | colors.fg = 22;24;38;2;245;245;245
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 32
7 | colors.e_hostname = 34
8 | colors.e_date = 38;2;66;66;88
9 | colors.e_box = 38;2;122;122;122
10 | colors.e_header = 1;4;36
11 | colors.e_user = 38;5;51
12 | colors.e_passwd = 4;2;38;5;80
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 34
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/nothing.ini:
--------------------------------------------------------------------------------
1 | colors.bg = -
2 | colors.fg = 24;39m[?25l[-
3 | colors.err = -
4 | colors.s_wayland = -
5 | colors.s_xorg = -
6 | colors.s_shell = -
7 | colors.e_hostname = -
8 | colors.e_date = 30
9 | colors.e_box = -
10 | colors.e_header = 30
11 | colors.e_user = -
12 | colors.e_passwd = 24;30
13 | colors.e_badpasswd = -
14 | colors.e_key = -
15 | chars.hb = -
16 | chars.vb = -
17 | chars.ctl = -
18 | chars.ctr = -
19 | chars.cbl = -
20 | chars.cbr = -
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/old-blue.ini:
--------------------------------------------------------------------------------
1 | colors.bg = 48;2;0;0;255
2 | colors.fg = 22;24;39;48;2;0;0;255
3 | colors.err = 1;31
4 | colors.s_wayland = 38;2;255;174;66
5 | colors.s_xorg = 38;2;37;175;255
6 | colors.s_shell = 38;2;34;140;34
7 | colors.e_hostname = 38;2;255;64;64
8 | colors.e_date = 38;2;144;144;144
9 | colors.e_box = 34
10 | colors.e_header = 4;38;2;0;255;0
11 | colors.e_user = 36
12 | colors.e_passwd = 4;38;2;245;245;205
13 | colors.e_badpasswd = 3;4;31
14 | colors.e_key = 1;31;48;2;255;174;66
15 | chars.hb = █
16 | chars.vb = █
17 | chars.ctl = █
18 | chars.ctr = █
19 | chars.cbl = █
20 | chars.cbr = █
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = powewoff
25 | strings.f_reboot = rewoot
26 | strings.f_refresh = rewresh
27 | strings.e_user = wuser
28 | strings.e_passwd = passwd
29 | strings.s_wayland = waywand
30 | strings.s_xorg = xworg
31 | strings.s_shell = swell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------
/themes/screenshots/cherry.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/cherry.png
--------------------------------------------------------------------------------
/themes/screenshots/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/default.png
--------------------------------------------------------------------------------
/themes/screenshots/kanagawa-dragon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/kanagawa-dragon.png
--------------------------------------------------------------------------------
/themes/screenshots/kanagawa-wave.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/kanagawa-wave.png
--------------------------------------------------------------------------------
/themes/screenshots/nature.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/nature.png
--------------------------------------------------------------------------------
/themes/screenshots/nord.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/nord.png
--------------------------------------------------------------------------------
/themes/screenshots/nothing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/nothing.png
--------------------------------------------------------------------------------
/themes/screenshots/old-blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/old-blue.png
--------------------------------------------------------------------------------
/themes/screenshots/tasteless.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalsai/lidm/f7139b16b546f400c5bbdf17e278beab72b2893b/themes/screenshots/tasteless.png
--------------------------------------------------------------------------------
/themes/tasteless.ini:
--------------------------------------------------------------------------------
1 | colors.bg = -
2 | colors.fg = 24
3 | colors.err = -
4 | colors.s_wayland = -
5 | colors.s_xorg = -
6 | colors.s_shell = -
7 | colors.e_hostname = -
8 | colors.e_date = -
9 | colors.e_box = -
10 | colors.e_header = -
11 | colors.e_user = -
12 | colors.e_passwd = -
13 | colors.e_badpasswd = -
14 | colors.e_key = -
15 | chars.hb = ─
16 | chars.vb = │
17 | chars.ctl = ┌
18 | chars.ctr = ┐
19 | chars.cbl = └
20 | chars.cbr = ┘
21 | functions.poweroff = F1
22 | functions.reboot = F2
23 | functions.refresh = F5
24 | strings.f_poweroff = poweroff
25 | strings.f_reboot = reboot
26 | strings.f_refresh = refresh
27 | strings.e_user = user
28 | strings.e_passwd = password
29 | strings.s_wayland = wayland
30 | strings.s_xorg = xorg
31 | strings.s_shell = shell
32 | behavior.include_defshell = true
33 | behavior.source = /etc/lidm.env
34 | behavior.source = /etc/locale.conf
35 | behavior.user_source = .lidm.env
36 |
--------------------------------------------------------------------------------