Last active
September 18, 2021 14:19
-
-
Save matyklug18/aaa2400a0c983ccb76a8c7bf962eadfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sys | |
import os | |
from i3ipc import Connection | |
from i3ipc import Event | |
i3 = Connection() | |
sep='|' | |
mx=10 | |
def get_workspace_str(ix): | |
if ix>=mx: ix=mx | |
if ix<=0: ix=1 | |
if ix in range(0,9+1): | |
inp = str(ix) | |
else: | |
inp='0' | |
st = (sep+' ')*(ix-1)+(sep+inp)+(sep+' ')*((mx+1)-ix-1)+sep | |
return st | |
while True: | |
wss=i3.get_workspaces() | |
ix=[w for w in wss if w.focused][0].num | |
sys.stdout.write(get_workspace_str(ix)+'\n') | |
sys.stdout.flush() | |
os.system("echo $(acpi | cut -d: -f2 | cut -d, -f1-2 | xargs) '' $(date '+%T %d.%m.%Y')") | |
sys.stdout.flush() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fileinput | |
from i3ipc import Connection | |
i3 = Connection() | |
def calc(x): | |
return [(x - 11)//20, (int(x) - 11)%20] | |
def get_inx(x): | |
res=calc(x) | |
if res[1] in range(0,4-1): | |
return 0 | |
else: | |
return res[0]+1 | |
for l in fileinput.input(): | |
ix=get_inx(int(l.strip().split(' ')[0])) | |
if ix in range(1,10+1): | |
i3.command(f"workspace {ix}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
stdbuf -i0 -o0 -e0 python i3-workspace-in.py | ./main.o | python i3-workspace-out.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------- | |
// TextBar v0.1.0 | |
// -------------- | |
// Usage: <text generator> | textbar | <input handler> | |
// | |
// Shows the last two lines from stdin on a bar | |
// Every odd line is on the left | |
// Every even line is on the right | |
// Updating one side at a time is not possible | |
// Line buffered | |
// Prints all mouse clicks to stdout | |
// In the format of `X Y` (without the '`') | |
#include <pthread.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#include <X11/Xlib.h> | |
#include <X11/Xatom.h> | |
#include <cairo.h> | |
#include <cairo-xlib.h> | |
Display* dpy; | |
Window win; | |
cairo_surface_t* sfc; | |
cairo_t* ctx; | |
char text[256] = {0}; | |
char text_other[256] = {0}; | |
int width; | |
//extern int errno; | |
// CONFIG | |
#define POSITION BOTTOM | |
#define FONT "FiraCode Nerd Font" | |
#define FONT_SIZE 16 | |
#define BG_COLOR 0.157, 0.165, 0.212 | |
#define FG_COLOR 0.973, 0.973, 0.949 | |
// COMPUTATION | |
#define HEIGHT FONT_SIZE*2 | |
#define FONT_POS FONT_SIZE*1.4 | |
void init() { | |
XInitThreads(); | |
dpy = XOpenDisplay(NULL); | |
int screen = DefaultScreen(dpy); | |
width = DisplayWidth(dpy, screen); | |
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, HEIGHT, 0, 0, 0); | |
XSelectInput(dpy, win, ButtonPressMask | StructureNotifyMask | ExposureMask); | |
Atom type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); | |
long value = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); | |
XChangeProperty(dpy, win, type, | |
XA_ATOM, 32, PropModeReplace, (unsigned char *) &value, 1); | |
#if POSITION==BOTTOM | |
XMoveWindow(dpy, win, 0, DisplayHeight(dpy, screen)); | |
#elif POSITION=TOP | |
XMoveWindow(dpy, win, 0, 0); | |
#endif | |
XMapWindow(dpy, win); | |
sfc = cairo_xlib_surface_create(dpy, win, DefaultVisual(dpy, screen), DisplayWidth(dpy, screen), HEIGHT); | |
ctx = cairo_create(sfc); | |
} | |
pthread_mutex_t do_paint; | |
void paint() { | |
pthread_mutex_lock(&do_paint); | |
cairo_push_group(ctx); | |
cairo_set_source_rgb(ctx, BG_COLOR); | |
cairo_paint(ctx); | |
cairo_move_to(ctx, FONT_SIZE / 2, FONT_POS); | |
cairo_select_font_face(ctx, FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | |
cairo_set_font_size(ctx, FONT_SIZE); | |
cairo_set_source_rgb(ctx, FG_COLOR); | |
cairo_show_text(ctx, text); | |
cairo_text_extents_t extents; | |
cairo_text_extents (ctx, text_other, &extents); | |
cairo_move_to(ctx, (width-extents.width) - FONT_SIZE / 2, FONT_POS); | |
cairo_show_text(ctx, text_other); | |
cairo_pop_group_to_source(ctx); | |
cairo_paint(ctx); | |
cairo_surface_flush(sfc); | |
XFlush(dpy); | |
pthread_mutex_unlock(&do_paint); | |
} | |
void update() { | |
while(1) { | |
fgets(text, 256, stdin); | |
fgets(text_other, 256, stdin); | |
text[strcspn(text, "\n")] = 0; | |
text_other[strcspn(text_other, "\n")] = 0; | |
paint(); | |
} | |
} | |
int main() { | |
init(); | |
pthread_mutex_init(&do_paint, NULL); | |
pthread_t update_thread_id; | |
if(pthread_create(&update_thread_id, NULL, update, NULL)) { | |
perror("pthread failed"); | |
} | |
while(1) { | |
XEvent e; | |
XNextEvent(dpy, &e); | |
if(e.type == ButtonPress) { | |
printf("%d %d\n", e.xbutton.x, e.xbutton.y); | |
fflush(stdout); | |
} else | |
if(e.type == ConfigureNotify) { | |
cairo_xlib_surface_set_size(sfc, e.xconfigure.width, e.xconfigure.height); | |
} else | |
if(e.type == Expose) { | |
paint(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment