summaryrefslogtreecommitdiff
path: root/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'gui.c')
-rw-r--r--gui.c115
1 files changed, 0 insertions, 115 deletions
diff --git a/gui.c b/gui.c
deleted file mode 100644
index 12f8f47..0000000
--- a/gui.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * LimoX - The Linux on mobile XMPP chat client
- * Copyright (C) 2022 xengineering
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-
-#include <SDL2/SDL.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "xmpp.h"
-
-
-struct GuiContext {
- bool quit;
- SDL_Event event;
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Texture* texture;
- uint32_t* pixels;
- int xmpp_fd;
-};
-
-
-struct GuiContext *init() {
- struct GuiContext *ctx = malloc(sizeof(struct GuiContext));
-
- ctx->quit = false;
- ctx->xmpp_fd = -1;
-
- ctx->pixels = malloc(sizeof(uint32_t) * 640 * 480);
- memset(ctx->pixels, 255, 640 * 480 * sizeof(uint32_t));
-
- SDL_Init(SDL_INIT_VIDEO);
-
- return ctx;
-}
-
-void deinit(struct GuiContext *ctx) {
-
- // TODO this seems to end in memory access errors but ... why?
- //SDL_DestroyTexture(texture);
- //SDL_DestroyRenderer(renderer);
-
- SDL_Quit();
-
- free(ctx->pixels);
- free(ctx);
-}
-
-bool create_window(struct GuiContext *ctx) {
-
- ctx->window = SDL_CreateWindow("LimoX",
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480,
- SDL_WINDOW_RESIZABLE
- );
-
- ctx->renderer = SDL_CreateRenderer(ctx->window, -1, 0);
- ctx->texture = SDL_CreateTexture(ctx->renderer, SDL_PIXELFORMAT_ARGB8888,
- SDL_TEXTUREACCESS_STATIC, 640, 480);
-
- return ctx->window != NULL;
-}
-
-void gui_run(void) {
-
- struct GuiContext *ctx = init();
-
- fprintf(stderr, "SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
- if (!create_window(ctx)) {
- fprintf(stderr, "Failed to create SDL2 window!\n");
- return;
- }
-
- while (!ctx->quit) {
- SDL_UpdateTexture(ctx->texture, NULL, ctx->pixels, 640 * sizeof(uint32_t));
- SDL_WaitEvent(&ctx->event);
- switch (ctx->event.type) {
- case SDL_QUIT:
- ctx->quit = true;
- break;
- case SDL_MOUSEBUTTONDOWN:
- if (ctx->xmpp_fd == -1) {
- ctx->xmpp_fd = xmpp_connect();
- } else {
- close(ctx->xmpp_fd);
- ctx->xmpp_fd = -1;
- printf("Closed XMPP connection.\n");
- }
- break;
- }
- SDL_RenderClear(ctx->renderer);
- SDL_RenderCopy(ctx->renderer, ctx->texture, NULL, NULL);
- SDL_RenderPresent(ctx->renderer);
- }
-
- SDL_DestroyWindow(ctx->window);
- deinit(ctx);
-
-}