2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
static struct screen *window_clock_init(struct window_mode_entry *,
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
struct cmd_find_state *, struct args *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_clock_free(struct window_mode_entry *);
|
|
|
|
static void window_clock_resize(struct window_mode_entry *, u_int, u_int);
|
|
|
|
static void window_clock_key(struct window_mode_entry *, struct client *,
|
2018-12-18 13:20:44 +00:00
|
|
|
struct session *, struct winlink *, key_code,
|
|
|
|
struct mouse_event *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void window_clock_timer_callback(int, short, void *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_clock_draw_screen(struct window_mode_entry *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct window_mode window_clock_mode = {
|
2017-05-07 22:27:57 +00:00
|
|
|
.name = "clock-mode",
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
.init = window_clock_init,
|
|
|
|
.free = window_clock_free,
|
|
|
|
.resize = window_clock_resize,
|
|
|
|
.key = window_clock_key,
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct window_clock_mode_data {
|
|
|
|
struct screen screen;
|
|
|
|
time_t tim;
|
2015-08-28 12:25:42 +00:00
|
|
|
struct event timer;
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2014-03-31 21:34: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
|
|
|
{ { 1,1,1,1,1 }, /* 8 */
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 },
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 } },
|
|
|
|
{ { 1,1,1,1,1 }, /* 9 */
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 },
|
|
|
|
{ 0,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 } },
|
|
|
|
{ { 0,0,0,0,0 }, /* : */
|
|
|
|
{ 0,0,1,0,0 },
|
|
|
|
{ 0,0,0,0,0 },
|
|
|
|
{ 0,0,1,0,0 },
|
|
|
|
{ 0,0,0,0,0 } },
|
|
|
|
{ { 1,1,1,1,1 }, /* A */
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 },
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,0,0,0,1 } },
|
|
|
|
{ { 1,1,1,1,1 }, /* P */
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,1,1,1,1 },
|
|
|
|
{ 1,0,0,0,0 },
|
|
|
|
{ 1,0,0,0,0 } },
|
|
|
|
{ { 1,0,0,0,1 }, /* M */
|
|
|
|
{ 1,1,0,1,1 },
|
|
|
|
{ 1,0,1,0,1 },
|
|
|
|
{ 1,0,0,0,1 },
|
|
|
|
{ 1,0,0,0,1 } },
|
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_clock_timer_callback(__unused int fd, __unused short events, void *arg)
|
2015-08-28 12:25:42 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_mode_entry *wme = arg;
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_clock_mode_data *data = wme->data;
|
2015-08-28 12:25:42 +00:00
|
|
|
struct tm now, then;
|
|
|
|
time_t t;
|
|
|
|
struct timeval tv = { .tv_sec = 1 };
|
|
|
|
|
|
|
|
evtimer_del(&data->timer);
|
|
|
|
evtimer_add(&data->timer, &tv);
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
if (TAILQ_FIRST(&wp->modes) != wme)
|
|
|
|
return;
|
|
|
|
|
2015-08-28 12:25:42 +00:00
|
|
|
t = time(NULL);
|
|
|
|
gmtime_r(&t, &now);
|
|
|
|
gmtime_r(&data->tim, &then);
|
|
|
|
if (now.tm_min == then.tm_min)
|
|
|
|
return;
|
|
|
|
data->tim = t;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_draw_screen(wme);
|
2019-03-12 11:16:49 +00:00
|
|
|
wp->flags |= PANE_REDRAW;
|
2015-08-28 12:25:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static struct screen *
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_init(struct window_mode_entry *wme,
|
|
|
|
__unused struct cmd_find_state *fs, __unused struct args *args)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window_clock_mode_data *data;
|
|
|
|
struct screen *s;
|
2015-08-28 12:25:42 +00:00
|
|
|
struct timeval tv = { .tv_sec = 1 };
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
wme->data = data = xmalloc(sizeof *data);
|
2009-06-01 22:58:49 +00:00
|
|
|
data->tim = time(NULL);
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
evtimer_set(&data->timer, window_clock_timer_callback, wme);
|
2015-08-28 12:25:42 +00:00
|
|
|
evtimer_add(&data->timer, &tv);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
s = &data->screen;
|
|
|
|
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
|
|
|
s->mode &= ~MODE_CURSOR;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_draw_screen(wme);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_free(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_clock_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-08-28 12:25:42 +00:00
|
|
|
evtimer_del(&data->timer);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_free(&data->screen);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_clock_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2013-02-05 11:08:59 +00:00
|
|
|
screen_resize(s, sx, sy, 0);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_draw_screen(wme);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_key(struct window_mode_entry *wme, __unused struct client *c,
|
2018-12-18 13:20:44 +00:00
|
|
|
__unused struct session *s, __unused struct winlink *wl,
|
|
|
|
__unused key_code key, __unused struct mouse_event *m)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
window_pane_reset_mode(wme->wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_clock_draw_screen(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_clock_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2009-11-26 23:13:47 +00:00
|
|
|
int colour, style;
|
2014-03-31 21:34:08 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct grid_cell gc;
|
|
|
|
char tim[64], *ptr;
|
|
|
|
time_t t;
|
|
|
|
struct tm *tm;
|
|
|
|
u_int i, j, x, y, idx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
colour = options_get_number(wp->window->options, "clock-mode-colour");
|
|
|
|
style = options_get_number(wp->window->options, "clock-mode-style");
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&ctx, s);
|
2014-03-31 21:34:08 +00:00
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
tm = localtime(&t);
|
|
|
|
if (style == 0) {
|
|
|
|
strftime(tim, sizeof tim, "%l:%M ", localtime(&t));
|
|
|
|
if (tm->tm_hour >= 12)
|
|
|
|
strlcat(tim, "PM", sizeof tim);
|
|
|
|
else
|
|
|
|
strlcat(tim, "AM", sizeof tim);
|
|
|
|
} else
|
|
|
|
strftime(tim, sizeof tim, "%H:%M", tm);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
screen_write_clearscreen(&ctx, 8);
|
2014-03-31 21:34:08 +00:00
|
|
|
|
|
|
|
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
|
|
|
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
|
|
|
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
|
|
|
|
y = screen_size_y(s) / 2;
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, x, y, 0);
|
2014-03-31 21:34:08 +00:00
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2016-07-15 00:42:56 +00:00
|
|
|
gc.fg = colour;
|
2014-03-31 21:34:08 +00:00
|
|
|
screen_write_puts(&ctx, &gc, "%s", tim);
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
|
|
|
y = (screen_size_y(s) / 2) - 3;
|
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2016-07-15 00:42:56 +00:00
|
|
|
gc.bg = colour;
|
2014-03-31 21:34:08 +00:00
|
|
|
for (ptr = tim; *ptr != '\0'; ptr++) {
|
|
|
|
if (*ptr >= '0' && *ptr <= '9')
|
|
|
|
idx = *ptr - '0';
|
|
|
|
else if (*ptr == ':')
|
|
|
|
idx = 10;
|
|
|
|
else if (*ptr == 'A')
|
|
|
|
idx = 11;
|
|
|
|
else if (*ptr == 'P')
|
|
|
|
idx = 12;
|
|
|
|
else if (*ptr == 'M')
|
|
|
|
idx = 13;
|
|
|
|
else {
|
|
|
|
x += 6;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
for (i = 0; i < 5; i++) {
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, x + i, y + j, 0);
|
2014-03-31 21:34:08 +00:00
|
|
|
if (window_clock_table[idx][j][i])
|
|
|
|
screen_write_putc(&ctx, &gc, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x += 6;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|