2018-08-14 11:13:38 +03:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2018 K. Lange
|
|
|
|
*
|
|
|
|
* background - Draw a desktop wallpaper.
|
|
|
|
*
|
|
|
|
* TODO: This is a very minimal wallpaper renderer.
|
|
|
|
* ToaruOS-mainline, before it went all Python,
|
|
|
|
* included a more complete wallpaper application,
|
|
|
|
* which supported icons and config files.
|
|
|
|
*/
|
2018-02-25 14:42:04 +03:00
|
|
|
#include <stdio.h>
|
2018-03-01 15:31:23 +03:00
|
|
|
#include <unistd.h>
|
2018-03-01 09:10:57 +03:00
|
|
|
#include <sys/utsname.h>
|
2018-02-25 14:42:04 +03:00
|
|
|
|
2018-03-19 05:38:11 +03:00
|
|
|
#include <toaru/yutani.h>
|
|
|
|
#include <toaru/graphics.h>
|
2018-03-01 09:10:57 +03:00
|
|
|
|
2018-02-25 11:14:43 +03:00
|
|
|
static yutani_t * yctx;
|
2018-03-01 09:10:57 +03:00
|
|
|
static yutani_window_t * wallpaper_window;
|
|
|
|
static gfx_context_t * wallpaper_ctx;
|
2018-03-01 15:45:37 +03:00
|
|
|
static sprite_t * wallpaper;
|
2018-02-25 11:14:43 +03:00
|
|
|
|
2018-02-25 14:42:04 +03:00
|
|
|
static void draw_background(int width, int height) {
|
2018-03-01 15:45:37 +03:00
|
|
|
|
|
|
|
float x = (float)wallpaper_window->width / (float)wallpaper->width;
|
|
|
|
float y = (float)wallpaper_window->height / (float)wallpaper->height;
|
|
|
|
|
|
|
|
int nh = (int)(x * (float)wallpaper->height);
|
|
|
|
int nw = (int)(y * (float)wallpaper->width);
|
|
|
|
|
|
|
|
if (nw == wallpaper->width && nh == wallpaper->height) {
|
|
|
|
// special case
|
|
|
|
draw_sprite(wallpaper_ctx, wallpaper, 0, 0);
|
|
|
|
} else if (nw >= width) {
|
2018-03-29 15:33:56 +03:00
|
|
|
draw_sprite_scaled(wallpaper_ctx, wallpaper, ((int)wallpaper_window->width - nw) / 2, 0, nw+2, wallpaper_window->height);
|
2018-03-01 15:45:37 +03:00
|
|
|
} else {
|
2018-03-29 15:33:56 +03:00
|
|
|
draw_sprite_scaled(wallpaper_ctx, wallpaper, 0, ((int)wallpaper_window->height - nh) / 2, wallpaper_window->width+2, nh);
|
2018-03-01 15:45:37 +03:00
|
|
|
}
|
2018-03-01 09:10:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void resize_finish_wallpaper(int width, int height) {
|
|
|
|
yutani_window_resize_accept(yctx, wallpaper_window, width, height);
|
|
|
|
reinit_graphics_yutani(wallpaper_ctx, wallpaper_window);
|
2018-02-25 14:42:04 +03:00
|
|
|
draw_background(width, height);
|
2018-03-01 09:10:57 +03:00
|
|
|
yutani_window_resize_done(yctx, wallpaper_window);
|
|
|
|
yutani_flip(yctx, wallpaper_window);
|
|
|
|
}
|
|
|
|
|
2018-02-25 11:14:43 +03:00
|
|
|
int main (int argc, char ** argv) {
|
2018-03-01 15:45:37 +03:00
|
|
|
|
2018-05-10 15:54:19 +03:00
|
|
|
if (argc < 2 || strcmp(argv[1],"--really")) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Desktop environment wallpaper\n"
|
|
|
|
"\n"
|
|
|
|
" Renders the desktop wallpaper. You probably don't want\n"
|
|
|
|
" to be running this directly - it is started by the\n"
|
|
|
|
" session manager along with the panel.\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-01 15:45:37 +03:00
|
|
|
wallpaper = malloc(sizeof(sprite_t));
|
|
|
|
load_sprite(wallpaper, "/usr/share/wallpaper.bmp");
|
|
|
|
wallpaper->alpha = 0;
|
|
|
|
|
2018-02-25 11:14:43 +03:00
|
|
|
yctx = yutani_init();
|
2018-08-01 03:21:13 +03:00
|
|
|
if (!yctx) {
|
|
|
|
fprintf(stderr, "%s: failed to connect to compositor\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
2018-03-01 09:10:57 +03:00
|
|
|
|
|
|
|
/* wallpaper */
|
|
|
|
wallpaper_window = yutani_window_create(yctx, yctx->display_width, yctx->display_height);
|
|
|
|
yutani_window_move(yctx, wallpaper_window, 0, 0);
|
|
|
|
yutani_set_stack(yctx, wallpaper_window, YUTANI_ZORDER_BOTTOM);
|
|
|
|
|
|
|
|
wallpaper_ctx = init_graphics_yutani(wallpaper_window);
|
2018-02-25 14:42:04 +03:00
|
|
|
draw_background(yctx->display_width, yctx->display_height);
|
2018-03-01 09:10:57 +03:00
|
|
|
yutani_flip(yctx, wallpaper_window);
|
|
|
|
|
2018-02-25 11:14:43 +03:00
|
|
|
int should_exit = 0;
|
|
|
|
|
|
|
|
while (!should_exit) {
|
|
|
|
yutani_msg_t * m = yutani_poll(yctx);
|
|
|
|
if (m) {
|
|
|
|
switch (m->type) {
|
2018-02-25 14:42:04 +03:00
|
|
|
case YUTANI_MSG_WELCOME:
|
2018-03-01 09:10:57 +03:00
|
|
|
yutani_window_resize_offer(yctx, wallpaper_window, yctx->display_width, yctx->display_height);
|
2018-03-01 15:31:23 +03:00
|
|
|
break;
|
2018-02-25 14:42:04 +03:00
|
|
|
case YUTANI_MSG_RESIZE_OFFER:
|
|
|
|
{
|
|
|
|
struct yutani_msg_window_resize * wr = (void*)m->data;
|
2018-03-01 09:10:57 +03:00
|
|
|
if (wr->wid == wallpaper_window->wid) {
|
|
|
|
resize_finish_wallpaper(wr->width, wr->height);
|
|
|
|
}
|
2018-02-25 14:42:04 +03:00
|
|
|
}
|
|
|
|
break;
|
2018-02-25 11:14:43 +03:00
|
|
|
case YUTANI_MSG_SESSION_END:
|
|
|
|
should_exit = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
2018-03-01 09:10:57 +03:00
|
|
|
yutani_close(yctx, wallpaper_window);
|
2018-02-25 11:14:43 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|