diff options
| author | Jack Jamison <jackqjamison@gmail.com> | 2025-10-17 18:21:51 -0400 |
|---|---|---|
| committer | Jack Jamison <jackqjamison@gmail.com> | 2025-10-17 18:21:51 -0400 |
| commit | ec8c94dc43db11c79ef58b212cacfadec09bb59c (patch) | |
| tree | dac513e9acb40b2d6f606031bb4d9299e2e8c423 | |
| parent | 7abba4bd6aea943870bfd571866e36a6167c80a2 (diff) | |
lines argument
| -rw-r--r-- | args.c | 26 | ||||
| -rw-r--r-- | args.h | 8 | ||||
| -rw-r--r-- | font.c | 2 | ||||
| -rw-r--r-- | graphics.c | 10 | ||||
| -rw-r--r-- | layer_surface.c | 25 | ||||
| -rw-r--r-- | main.c | 4 | ||||
| -rw-r--r-- | state.h | 6 |
7 files changed, 66 insertions, 15 deletions
@@ -0,0 +1,26 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <getopt.h> + +#include "args.h" + +void parse_args(client_state* state, int argc, char* argv[]) { + static struct option long_opts[] = { + {"lines", required_argument, 0, 'l'}, + {0, 0, 0, 0} + }; + + int opt; + int long_index = 0; + while ((opt = getopt_long(argc, argv, "l:", long_opts, &long_index)) != -1) { + switch (opt) { + case 'l': + state->lines = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: NOT WHAT YOU TYPED\n"); + break; + } + } +} @@ -0,0 +1,8 @@ +#ifndef ARGS_H_ +#define ARGS_H_ + +#include "state.h" + +void parse_args(client_state* state, int argc, char* argv[]); + +#endif @@ -61,7 +61,7 @@ bool freetype_init(client_state* state, const char* file) { return false; } state->load_flags = FT_LOAD_RENDER | FT_LOAD_TARGET_(FT_RENDER_MODE_SDF); - state->line_height = (float)(state->ft_face->size->metrics.height >> 6); + state->line_height = state->ft_face->size->metrics.height >> 6; return true; } @@ -128,19 +128,15 @@ void render_frame(client_state *state) { glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // draw text + // bind vertex and texture glBindVertexArray(state->input_buffer_text.vao); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state->atlas.texture); + // bind shader and draw glUseProgram(state->text_shader); glUniform2f(state->screen_size_uniform, state->width, state->height); - glUniform2f(state->offset_uniform, 0.0f, 0.0f); - glDrawElements(GL_TRIANGLES, state->input_buffer_text.num_elements, GL_UNSIGNED_INT, 0); - - // draw second text a line higher - glUniform2f(state->offset_uniform, 0.0f, state->line_height); + glUniform2f(state->offset_uniform, 0.0f, state->line_height * (state->lines + 0.15f)); glDrawElements(GL_TRIANGLES, state->input_buffer_text.num_elements, GL_UNSIGNED_INT, 0); // present screen diff --git a/layer_surface.c b/layer_surface.c index eb23da9..017ac8a 100644 --- a/layer_surface.c +++ b/layer_surface.c @@ -1,18 +1,33 @@ #include "./state.h" +#include "array.h" struct zwlr_layer_surface_v1_listener layer_surface_listener; void create_surface(client_state* state) { + // figure out anchor + uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + if (state->lines > 0) { + anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + } + + // figure out size + uint32_t desired_width = 0; + uint32_t desired_height = state->line_height; + if (state->lines > 0) { + desired_width = 600; // figure out later + desired_height = (state->lines + 1) * state->line_height; + } + + // create surface state->surface = wl_compositor_create_surface(state->compositor); state->layer_surface = zwlr_layer_shell_v1_get_layer_surface( state->layer_shell, state->surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swenu"); zwlr_layer_surface_v1_add_listener(state->layer_surface, &layer_surface_listener, state); - zwlr_layer_surface_v1_set_size(state->layer_surface, 600, 400); - zwlr_layer_surface_v1_set_anchor(state->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | - ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | - ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | - ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT); + zwlr_layer_surface_v1_set_size(state->layer_surface, desired_width, desired_height); + zwlr_layer_surface_v1_set_anchor(state->layer_surface, anchor); zwlr_layer_surface_v1_set_exclusive_zone(state->layer_surface, -1); zwlr_layer_surface_v1_set_margin(state->layer_surface, 0, 0, 0, 0); zwlr_layer_surface_v1_set_keyboard_interactivity(state->layer_surface, ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE); @@ -9,6 +9,7 @@ #include "input_field.h" #include "font.h" #include "array.h" +#include "args.h" void poll_events(client_state* state); @@ -30,11 +31,12 @@ void read_stdin(client_state* state) { free(line); } -int main() { +int main(int argc, char* argv[]) { client_state state = {0}; state.running = true; state.input_buffer = array_new(char, 0); + parse_args(&state, argc, argv); read_stdin(&state); // find font @@ -41,6 +41,7 @@ typedef struct { typedef struct { char* text; size_t pixel_len; + text_buffer_t text_buffer; } item_t; typedef struct { @@ -84,7 +85,10 @@ typedef struct { FT_Face ft_face; FT_Int32 load_flags; atlas_t atlas; - float line_height; + uint32_t line_height; + + // arguments + int lines; // state char* input_buffer; |
