Skip to content

Commit 01d94b3

Browse files
committed
(#3) Added configurable highlight timeout
2 parents a8f66af + 05f5326 commit 01d94b3

File tree

5 files changed

+79
-43
lines changed

5 files changed

+79
-43
lines changed

src/highlightwindow.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#ifndef HIGHLIGHT_WINDOW_H
3+
#define HIGHLIGHT_WINDOW_H
4+
5+
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity);
6+
7+
#endif

src/highlightwindow_linux.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <X11/Xlib.h>
2+
#include <X11/Xutil.h>
3+
#include <stdio.h>
4+
#include "highlightwindow.h"
5+
6+
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity) {
7+
// Display *dpy;
8+
// XVisualInfo vinfo;
9+
// int depth;
10+
// XVisualInfo *visual_list;
11+
// XVisualInfo visual_template;
12+
// int nxvisuals;
13+
// int i;
14+
// XSetWindowAttributes attrs;
15+
// Window parent;
16+
// Visual *visual;
17+
18+
// dpy = XOpenDisplay(NULL);
19+
20+
// nxvisuals = 0;
21+
// visual_template.screen = DefaultScreen(dpy);
22+
// visual_list = XGetVisualInfo (dpy, VisualScreenMask, &visual_template, &nxvisuals);
23+
24+
// for (i = 0; i < nxvisuals; ++i)
25+
// {
26+
// printf(" %3d: visual 0x%lx class %d (%s) depth %d\n",
27+
// i,
28+
// visual_list[i].visualid,
29+
// visual_list[i].depth);
30+
// }
31+
32+
// if (!XMatchVisualInfo(dpy, XDefaultScreen(dpy), 32, TrueColor, &vinfo))
33+
// {
34+
// fprintf(stderr, "no such visual\n");
35+
// return;
36+
// }
37+
38+
// printf("Matched visual 0x%lx class %d (%s) depth %d\n",
39+
// vinfo.visualid,
40+
// vinfo.depth);
41+
42+
// parent = XDefaultRootWindow(dpy);
43+
44+
// XSync(dpy, True);
45+
46+
// printf("creating RGBA child\n");
47+
48+
// visual = vinfo.visual;
49+
// depth = vinfo.depth;
50+
51+
// attrs.colormap = XCreateColormap(dpy, XDefaultRootWindow(dpy), visual, AllocNone);
52+
// attrs.background_pixel = 0;
53+
// attrs.border_pixel = 0;
54+
55+
// XCreateWindow(dpy, parent, 10, 10, 150, 100, 0, depth, InputOutput,
56+
// visual, CWBackPixel | CWColormap | CWBorderPixel, &attrs);
57+
58+
// XSync(dpy, True);
59+
60+
// printf("No error\n");
61+
}

src/window_macos.mm renamed to src/highlightwindow_macos.mm

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
#include "window.h"
1+
#include "highlightwindow.h"
22
#import <Cocoa/Cocoa.h>
33

4-
5-
Window::Window(int x, int y, int width, int height) {
6-
this->_x = x;
7-
this->_y = y;
8-
this->_width = width;
9-
this->_height = height;
10-
}
11-
12-
void Window::show(int duration, float opacity) {
4+
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity) {
135
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
146
[NSApplication sharedApplication];
157

16-
NSRect frame = NSMakeRect(this->_x, this->_y, this->_width, this->_height);
8+
NSRect frame = NSMakeRect(x, y, width, height);
179
NSUInteger styleMask = NSWindowStyleMaskBorderless;
1810
NSWindow * window = [[[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease];
1911
[window setBackgroundColor:[NSColor redColor]];

src/window_win32.cc renamed to src/highlightwindow_win32.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@
33
#endif
44

55
#include <windows.h>
6-
#include <cstdio>
7-
#include "window.h"
6+
#include <stdio.h>
7+
#include "highlightwindow.h"
88

99
#define ID_CLOSE_TIMER 1001
1010

1111
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
1212

13-
Window::Window(int x, int y, int width, int height) {
14-
this->_x = x;
15-
this->_y = y;
16-
this->_width = width;
17-
this->_height = height;
18-
}
19-
20-
void Window::show(int duration, float opacity) {
13+
void showHighlightWindow(int x, int y, int width, int height, int duration, float opacity) {
2114
// Register the window class.
2215
const wchar_t CLASS_NAME[] = L"Highlight Window Class";
2316

@@ -35,10 +28,10 @@ void Window::show(int duration, float opacity) {
3528
CLASS_NAME,
3629
0,
3730
WS_POPUP,
38-
this->_x,
39-
this->_y,
40-
this->_width,
41-
this->_height,
31+
x,
32+
y,
33+
width,
34+
height,
4235
NULL,
4336
NULL,
4437
NULL,
@@ -51,7 +44,7 @@ void Window::show(int duration, float opacity) {
5144
return;
5245
}
5346

54-
SetTimer(hwnd, ID_CLOSE_TIMER, 2000, NULL);
47+
SetTimer(hwnd, ID_CLOSE_TIMER, duration * 1000, NULL);
5548
ShowWindow(hwnd, 1);
5649

5750
MSG msg = { };

src/window.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)