taskbar.c
来自「CS架构的多平台的GUI系统」· C语言 代码 · 共 263 行
C
263 行
/*************************************************************************** begin : Tue Oct 5 2004 copyright : (C) 2004 - 2005 by Alper Akcan email : distchx@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of the * * License, or (at your option) any later version. * * * ***************************************************************************/#include "desktop.h"void taskbar_progs_handler_r (s_window_t *window, s_event_t *event, s_handler_t *handler){ int w; int px; int py; int pos; tbar_data_t *tbar_data; tbar_progs_t *tbar_progs; s_desktop_client_t *desktopc; tbar_data = (tbar_data_t *) window->client->user_data; tbar_progs = (tbar_progs_t *) tbar_data->tbar_progs; px = event->mouse->x - tbar_progs->rect.x; py = event->mouse->y - tbar_progs->rect.y; if (tbar_progs->desktop->clients->nb_elt <= 0) { return; } w = ((tbar_progs->rect.w / tbar_progs->desktop->clients->nb_elt) > 125) ? 125 : (tbar_progs->rect.w / tbar_progs->desktop->clients->nb_elt); if ((px > 0) && (px < w * tbar_progs->desktop->clients->nb_elt)) { pos = px / w; } else { return; } desktopc = (s_desktop_client_t *) s_list_get(tbar_progs->desktop->clients, pos); if (desktopc != NULL) { s_socket_request(window, SOC_DATA_DESKTOP, desktopc->id); }}void taskbar_progs_draw_client (tbar_progs_t *tbar_progs, s_surface_t *surface, s_desktop_client_t *client, int x, int y, int w, int h){ int x_; int w_ = 0; int _w = 0; char *text; s_font_t *font; x += 2; w -= 4; text = (char *) s_malloc(sizeof(char) * (50 + 1)); snprintf(text, 50, "%s", client->title); font = tbar_progs->prog_font; s_font_set_str(font, text); s_font_set_size(font, h - 8); s_font_get_glyph(font); s_image_get_handler(font->img); s_fillbox(surface, x, y, w, h, s_rgbcolor(surface, 123, 121, 115)); if (!client->pri) { for (x_ = w - 3; x_ >= 0; x_--) { s_putbox(surface, x + 1 + x_, y + 1, 1, h - 2, tbar_progs->prog_img[0]->buf); } x += 1; y += 1; } else { for (x_ = w - 3; x_ >= 0; x_--) { s_putbox(surface, x + 1 + x_, y + 1, 1, h - 2, tbar_progs->prog_img[1]->buf); } } y += 5; x += 4; w_ = font->img->w; if (font->img->w > (w - 8)) { w_ = w - 8; _w = font->img->w - (w - 8); } s_putboxpartrgba(surface, x, y, w_, font->img->h, font->img->w, font->img->h, font->img->rgba, 0, 0); s_free(text); s_image_uninit(font->img); s_image_init(&(font->img));}void taskbar_progs_draw (s_window_t *window){ int x; int pos; int w = 0; char *vbuf; s_surface_t *srf; tbar_data_t *tbar_data; tbar_progs_t *tbar_progs; s_desktop_client_t *desktopc; pos = 0; tbar_data = (tbar_data_t *) window->client->user_data; tbar_progs = (tbar_progs_t *) tbar_data->tbar_progs; if (tbar_progs->desktop->clients->nb_elt > 0) { w = ((tbar_progs->rect.w / tbar_progs->desktop->clients->nb_elt) > 125) ? 125 : (tbar_progs->rect.w / tbar_progs->desktop->clients->nb_elt); } srf = (s_surface_t *) s_malloc(sizeof(s_surface_t)); vbuf = (char *) s_malloc(window->surface->bytesperpixel * tbar_progs->rect.w * tbar_progs->rect.h + 1); s_getsurfacevirtual(srf, tbar_progs->rect.w, tbar_progs->rect.h, window->surface->bitsperpixel, vbuf); for (x = 0; x <= tbar_progs->rect.w; x++) { s_putboxpart(srf, x, 0, 1, tbar_progs->rect.h, 1, 30, tbar_progs->tbar_img->buf, 0, tbar_progs->rect.y); } while (!s_list_eol(tbar_progs->desktop->clients, pos)) { desktopc = (s_desktop_client_t *) s_list_get(tbar_progs->desktop->clients, pos); taskbar_progs_draw_client(tbar_progs, srf, desktopc, w * pos, 0, w, tbar_progs->rect.h); pos++; } s_putbox(window->surface, tbar_progs->rect.x, tbar_progs->rect.y, tbar_progs->rect.w, tbar_progs->rect.h, srf->vbuf); s_free(vbuf); s_free(srf);}void taskbar_start_menu_icon (s_window_t *window){ char *vbuf; s_surface_t *srf; tbar_data_t *tbar_data; tbar_smenu_t *tbar_smenu; tbar_data = (tbar_data_t *) window->client->user_data; tbar_smenu = (tbar_smenu_t *) tbar_data->tbar_smenu; srf = (s_surface_t *) s_malloc(sizeof(s_surface_t)); vbuf = (char *) s_malloc(window->surface->bytesperpixel * tbar_smenu->img->w * tbar_smenu->img->h + 1); s_getsurfacevirtual(srf, tbar_smenu->img->w, tbar_smenu->img->h, window->surface->bitsperpixel, vbuf); s_getbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->img->w, tbar_smenu->img->h, srf->vbuf); s_putboxrgba(srf, 0, 0, tbar_smenu->img->w, tbar_smenu->img->h, tbar_smenu->img->rgba); s_putbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->img->w, tbar_smenu->img->h, srf->vbuf); s_free(vbuf); s_free(srf);}void taskbar_start_menu_handler_p (s_window_t *window, s_event_t *event, s_handler_t *handler){ char *box; tbar_data_t *tbar_data; tbar_smenu_t *tbar_smenu; tbar_data = (tbar_data_t *) window->client->user_data; tbar_smenu = (tbar_smenu_t *) tbar_data->tbar_smenu; while (tbar_data->tbar_smenu->running) { usleep(20000); } box = (char *) s_malloc(tbar_smenu->rect.w * tbar_smenu->rect.h * window->surface->bytesperpixel); s_getbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->rect.w, tbar_smenu->rect.h, box); s_fillbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->rect.w + 2, tbar_smenu->rect.h + 2, s_rgbcolor(window->surface, 115, 117, 115)); s_fillbox(window->surface, tbar_smenu->rect.x + 1, tbar_smenu->rect.y + 1, tbar_smenu->rect.w + 1, tbar_smenu->rect.h + 1, s_rgbcolor(window->surface, 255, 255, 255)); s_putbox(window->surface, tbar_smenu->rect.x + 1, tbar_smenu->rect.y + 1, tbar_smenu->rect.w, tbar_smenu->rect.h, box); s_free(box); start_menu_start(window, tbar_data->tbar_smenu->progs, window->surface->buf.x, window->surface->buf.y);}void taskbar_start_menu_handler_rh (s_window_t *window, s_event_t *event, s_handler_t *handler){ int x; tbar_data_t *tbar_data; tbar_progs_t *tbar_progs; tbar_smenu_t *tbar_smenu; tbar_data = (tbar_data_t *) window->client->user_data; tbar_smenu = (tbar_smenu_t *) tbar_data->tbar_smenu; tbar_progs = (tbar_progs_t *) tbar_data->tbar_progs; for (x = 0; x <= tbar_smenu->rect.w + 2; x++) { s_putboxpart(window->surface, tbar_smenu->rect.x + x, tbar_smenu->rect.y, 1, tbar_smenu->rect.h + 2, 1, 30, tbar_progs->tbar_img->buf, 0, tbar_smenu->rect.y); } taskbar_start_menu_icon(window);}void taskbar_clock_popup_atexit (s_window_t *window){ tbar_data_t *tbar_data; tbar_clock_t *tbar_clock; tbar_data = (tbar_data_t *) window->parent->client->user_data; tbar_clock = (tbar_clock_t *) tbar_data->tbar_clock; tbar_clock->open = 0;}void taskbar_clock_popup_atevent (s_window_t *window, s_event_t *event){ int x; int y; tbar_data_t *tbar_data; tbar_clock_t *tbar_clock; if (event->type & MOUSE_EVENT) { tbar_data = (tbar_data_t *) window->parent->client->user_data; tbar_clock = (tbar_clock_t *) tbar_data->tbar_clock; x = event->mouse->x - window->parent->surface->buf.x; y = event->mouse->y - window->parent->surface->buf.y; if (!((x >= tbar_clock->rect.x) && (y >= tbar_clock->rect.y) && (x <= (tbar_clock->rect.x + tbar_clock->rect.w - 1)) && (y <= (tbar_clock->rect.y + tbar_clock->rect.h - 1)))) { s_client_quit(window); } }}void taskbar_clock_handler_o (s_window_t *window, s_event_t *event, s_handler_t *handler){ time_t t_; char *text; struct tm *t; int wday = 0; s_font_t *font; s_window_t *temp; tbar_data_t *tbar_data; tbar_clock_t *tbar_clock; int mon[] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5}; char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; char *mons[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; tbar_data = (tbar_data_t *) window->client->user_data; tbar_clock = tbar_data->tbar_clock; if (tbar_clock->open == 1) { return; } t_ = time(NULL); t = localtime(&t_); text = (char *) s_malloc(sizeof(char) * 256); s_client_init(&temp); s_window_new(temp, WINDOW_TEMP | NO_FORM, window); s_window_set_alwaysontop(temp, 1); /* W = C + Y + L + M + D (mod 7) Where: W is the day of the week (0 = Sunday, through 6 = Saturday) C is a code for the century from this table (for the Gregorian calendar only): 1400s, 1800s, 2200s 2 1800爄s爊ot燼爈eap爕ear 1500s, 1900s, 2300s牋牋
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?