Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osdd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
osdd
Commits
a696a907
Commit
a696a907
authored
4 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Add module support by osdd_abstract
parent
2f0f0ad2
No related branches found
No related tags found
No related merge requests found
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
Makefile
+4
-3
4 additions, 3 deletions
Makefile
display.c
+220
-238
220 additions, 238 deletions
display.c
display.h
+13
-34
13 additions, 34 deletions
display.h
osdd-set.c
+81
-0
81 additions, 0 deletions
osdd-set.c
osdd-set.h
+62
-0
62 additions, 0 deletions
osdd-set.h
osdd.c
+42
-27
42 additions, 27 deletions
osdd.c
with
422 additions
and
302 deletions
Makefile
+
4
−
3
View file @
a696a907
VERSION
=
1.1
ARCHIVE
=
osdd-
$(
VERSION
)
.tar.gz
CFLAGS
=
-g3
-Wall
-W
-Wno-parentheses
-Wstrict-prototypes
-Wmissing-prototypes
-Wundef
-Wredundant-decls
-std
=
gnu99
CFLAGS
=
-g3
-Wall
-W
-Wno-parentheses
-Wstrict-prototypes
-Wmissing-prototypes
-Wundef
-Wredundant-decls
-std
=
gnu99
-fsanitize
=
address
all
:
osdd osdc osd-batt osd-alsa
osdd
:
osdd.o util.o display.o
osdd
:
osdd.o util.o display.o
osdd-set.o
osdc
:
osdc.o util.o client.o
osd-batt
:
osd-batt.o util.o client.o
osd-alsa
:
osd-alsa.o util.o client.o
osdd
:
LDLIBS+=$(shell pkg-config --libs xft) -lXext -lX11
LDLIBS
+=
-fsanitize
=
address
osdc
:
LDLIBS+=-lX11
osd-batt
:
LDLIBS+=-lX11
...
...
This diff is collapsed.
Click to expand it.
display.c
+
220
−
238
View file @
a696a907
This diff is collapsed.
Click to expand it.
display.h
+
13
−
34
View file @
a696a907
...
...
@@ -8,26 +8,14 @@
#include
<stdbool.h>
#include
<X11/Xlib.h>
struct
osd_state
;
#include
"osdd-set.h"
#define OSD_MAX_LINE_LEN 256
enum
osd_line_type
{
OSD_TYPE_TEXT
,
OSD_TYPE_PERCENTAGE
,
OSD_TYPE_SLIDER
,
};
struct
display_state
;
struct
osd_line
{
enum
osd_line_type
type
;
char
*
fg_color
;
char
*
outline_color
;
int
outline_width
;
union
{
// Data dependent on type
char
text
[
OSD_MAX_LINE_LEN
];
// in UTF-8
unsigned
int
percent
;
// 0..100 for percentages and slider
}
u
;
#define OSD_MAX_LINE_LEN 256
struct
display_line
{
struct
osd_line
*
line
;
// Used internally
int
width
;
int
height
;
...
...
@@ -36,22 +24,13 @@ struct osd_line {
int
slider_unit
;
int
slider_space
;
int
slider_units
;
int
log
;
};
#define ALL_OSD_SET(set) for(int ALL_OSD_SET_i=0;ALL_OSD_SET_i<set.len;ALL_OSD_SET_i++) set->state[ALL_OSD_SET_i]
#define OSD_MAX_SET_LEN 10
struct
osd_set
{
struct
osd_state
*
state
[
OSD_MAX_SET_LEN
];
int
len
;
};
struct
osd_state
*
osd_state_new
(
Display
*
dpy
,
int
width
,
int
height
,
int
x
,
int
y
);
struct
osd_set
osd_set_new
(
Display
*
dpy
);
void
osd_free
(
struct
osd_state
*
osd
);
void
osd_set_font
(
struct
osd_state
*
osd
,
char
*
font_name
,
double
line_spacing
);
struct
osd_line
*
osd_add_line
(
struct
osd_state
*
osd
,
enum
osd_line_type
type
);
void
osd_show
(
struct
osd_state
*
osd
);
void
osd_hide
(
struct
osd_state
*
osd
);
void
osd_clear
(
struct
osd_state
*
osd
);
bool
osd_handle_event
(
struct
osd_state
*
osd
,
XEvent
*
ev
);
struct
osd_abstract
display_state_new
(
Display
*
dpy
,
int
width
,
int
height
,
int
x
,
int
y
);
void
display_free
(
struct
display_state
*
display
);
void
display_set_font
(
struct
display_state
*
display
,
char
*
font_name
,
double
line_spacing
);
struct
display_line
*
display_add_line
(
struct
display_state
*
display
,
struct
osd_line
*
line
);
void
display_show
(
struct
display_state
*
display
,
struct
osd_line
*
lines
,
int
num_lines
);
void
display_hide
(
struct
display_state
*
display
);
void
display_clear
(
struct
display_state
*
display
);
bool
display_handle_event
(
struct
display_state
*
display
,
XEvent
*
ev
);
This diff is collapsed.
Click to expand it.
osdd-set.c
0 → 100644
+
81
−
0
View file @
a696a907
/*
* On-screen Display
*
* (c) 2013--2014 Martin Mares <mj@ucw.cz>
* (c) 2020--2021 Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
*/
#include
<stdio.h>
#include
"osdd-set.h"
#include
"util.h"
struct
osd_line
*
osd_set_add_line
(
struct
osd_set
*
set
,
enum
osd_line_type
type
)
{
if
(
set
->
num_lines
>=
set
->
max_lines
)
{
set
->
max_lines
=
2
*
set
->
max_lines
+
1
;
set
->
lines
=
xrealloc
(
set
->
lines
,
sizeof
(
struct
osd_line
)
*
set
->
max_lines
);
}
struct
osd_line
*
l
=
&
set
->
lines
[
set
->
num_lines
++
];
l
->
type
=
type
;
l
->
fg_color
=
"green"
;
l
->
outline_color
=
"black"
;
l
->
outline_width
=
0
;
switch
(
l
->
type
)
{
case
OSD_TYPE_TEXT
:
l
->
u
.
text
[
0
]
=
0
;
break
;
case
OSD_TYPE_PERCENTAGE
:
case
OSD_TYPE_SLIDER
:
l
->
u
.
percent
=
0
;
break
;
default:
die
(
"osd_add_line: unknown type %d"
,
type
);
}
return
l
;
}
void
osd_set_show
(
struct
osd_set
*
set
)
{
for
(
int
i
=
0
;
i
<
set
->
len
;
i
++
)
{
set
->
elements
[
i
].
show
(
set
->
elements
[
i
].
context
,
set
->
lines
,
set
->
num_lines
);
}
}
void
osd_set_clear
(
struct
osd_set
*
set
)
{
for
(
int
i
=
0
;
i
<
set
->
len
;
i
++
)
{
set
->
elements
[
i
].
clear
(
set
->
elements
[
i
].
context
);
}
set
->
num_lines
=
0
;
}
bool
osd_set_handle_event
(
struct
osd_set
*
set
,
XEvent
*
ev
)
{
bool
r
=
0
;
for
(
int
i
=
0
;
i
<
set
->
len
;
i
++
)
{
if
(
set
->
elements
[
i
].
handle_event
)
r
|=
set
->
elements
[
i
].
handle_event
(
set
->
elements
[
i
].
context
,
ev
);
}
return
r
;
}
struct
osd_set
osd_set_new
(
void
)
{
struct
osd_set
set
;
set
.
len
=
0
;
set
.
num_lines
=
0
;
set
.
max_lines
=
0
;
set
.
lines
=
0
;
return
set
;
}
This diff is collapsed.
Click to expand it.
osdd-set.h
0 → 100644
+
62
−
0
View file @
a696a907
/*
* On-screen Display
*
* (c) 2013--2014 Martin Mares <mj@ucw.cz>
* (c) 2020--2021 Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
*/
#ifndef OSDD_SET_H
#define OSDD_SET_H
#include
<stdbool.h>
#include
<X11/Xlib.h>
struct
display_state
;
#define OSD_MAX_LINE_LEN 256
#define OSD_MAX_SET_LEN 64
#define OSD_ABSTRACT_NAME_LEN 64
enum
osd_line_type
{
OSD_TYPE_TEXT
,
OSD_TYPE_PERCENTAGE
,
OSD_TYPE_SLIDER
,
};
struct
osd_line
{
enum
osd_line_type
type
;
char
*
fg_color
;
char
*
outline_color
;
int
outline_width
;
union
{
// Data dependent on type
char
text
[
OSD_MAX_LINE_LEN
];
// in UTF-8
unsigned
int
percent
;
// 0..100 for percentages and slider
}
u
;
int
log
;
};
struct
osd_abstract
{
void
*
context
;
void
(
*
show
)(
void
*
context
,
struct
osd_line
*
lines
,
int
num_lines
);
void
(
*
clear
)(
void
*
context
);
bool
(
*
handle_event
)(
void
*
context
,
XEvent
*
ev
);
};
struct
osd_set
{
struct
osd_abstract
elements
[
OSD_MAX_SET_LEN
];
int
len
;
struct
osd_line
*
lines
;
int
num_lines
;
int
max_lines
;
};
struct
osd_set
osd_set_new
(
void
);
struct
osd_line
*
osd_set_add_line
(
struct
osd_set
*
set
,
enum
osd_line_type
type
);
void
osd_set_show
(
struct
osd_set
*
set
);
void
osd_set_clear
(
struct
osd_set
*
set
);
bool
osd_set_handle_event
(
struct
osd_set
*
set
,
XEvent
*
ev
);
#endif
This diff is collapsed.
Click to expand it.
osdd.c
+
42
−
27
View file @
a696a907
...
...
@@ -15,10 +15,12 @@
#include
<X11/Xlib.h>
#include
<X11/Xatom.h>
#
un
def DEBUG
#def
ine
DEBUG
#include
"util.h"
#include
"osdd-set.h"
#include
"display.h"
static
struct
osd_set
osd
;
#define FOREACHOSD for(int i=0;i<osd.len;i++)
...
...
@@ -26,7 +28,6 @@ static timestamp_t now;
/*** Options ***/
static
char
*
font_name
=
"times-64:bold"
;
static
char
*
default_color
=
"green"
;
static
char
*
default_outline_color
=
"black"
;
static
int
default_outline_width
=
2
;
...
...
@@ -35,7 +36,6 @@ static int default_min_duration = 250;
static
int
default_log
=
255
;
static
int
debug_mode
;
static
int
test_mode
;
static
double
line_spacing
=
0
.
2
;
static
const
char
short_opts
[]
=
"c:d:Df:m:o:O:s:"
;
...
...
@@ -92,10 +92,10 @@ parse_opts(int argc, char **argv)
debug_mode
=
1
;
break
;
case
'f'
:
font_name
=
optarg
;
//
font_name = optarg;
break
;
case
'l'
:
line_spacing
=
atof
(
optarg
);
//
line_spacing = atof(optarg);
break
;
case
'm'
:
default_min_duration
=
atoi
(
optarg
);
...
...
@@ -144,7 +144,7 @@ display_msg(struct msg *msg)
int
num_l
=
0
;
while
(
*
line
)
{
// The parser i
t
destructive, but it does not do any harm, since we display each message only once.
// The parser i
s
destructive, but it does not do any harm, since we display each message only once.
char
*
nl
=
strchr
(
line
,
'\n'
);
*
nl
++
=
0
;
...
...
@@ -162,22 +162,21 @@ display_msg(struct msg *msg)
}
DBG
(
"
\t
%s:%s
\n
"
,
key
,
val
);
struct
osd_line
*
l
[
OSD_MAX_SET_LEN
];
FOREACHOSD
l
[
i
]
=
0
;
struct
osd_line
*
l
=
0
;
if
(
!
key
[
0
])
{
FOREACHOSD
l
[
i
]
=
osd_add_line
(
osd
.
state
[
i
]
,
OSD_TYPE_TEXT
);
FOREACHOSD
sprintf
(
l
[
i
]
->
u
.
text
,
"%.*s"
,
OSD_MAX_LINE_LEN
,
val
);
l
=
osd_
set_
add_line
(
&
osd
,
OSD_TYPE_TEXT
);
sprintf
(
l
->
u
.
text
,
"%.*s"
,
OSD_MAX_LINE_LEN
,
val
);
}
else
if
(
!
strcmp
(
key
,
"percentage"
)
||
!
strcmp
(
key
,
"percent"
))
{
FOREACHOSD
l
[
i
]
=
osd_add_line
(
osd
.
state
[
i
]
,
OSD_TYPE_PERCENTAGE
);
FOREACHOSD
l
[
i
]
->
u
.
percent
=
atoi
(
val
);
l
=
osd_
set_
add_line
(
&
osd
,
OSD_TYPE_PERCENTAGE
);
l
->
u
.
percent
=
atoi
(
val
);
}
else
if
(
!
strcmp
(
key
,
"slider"
))
{
FOREACHOSD
l
[
i
]
=
osd_add_line
(
osd
.
state
[
i
]
,
OSD_TYPE_SLIDER
);
FOREACHOSD
l
[
i
]
->
u
.
percent
=
atoi
(
val
);
l
=
osd_
set_
add_line
(
&
osd
,
OSD_TYPE_SLIDER
);
l
->
u
.
percent
=
atoi
(
val
);
}
else
if
(
!
strcmp
(
key
,
"duration"
))
msg
->
max_light
=
now
+
atoi
(
val
);
...
...
@@ -191,21 +190,21 @@ display_msg(struct msg *msg)
outline_color
=
val
;
else
if
(
!
strcmp
(
key
,
"outline-width"
))
outline_width
=
atoi
(
val
);
FOREACHOSD
if
(
l
[
i
]
)
if
(
l
)
{
num_l
++
;
l
[
i
]
->
fg_color
=
fg_color
;
l
[
i
]
->
outline_color
=
outline_color
;
l
[
i
]
->
outline_width
=
outline_width
;
l
[
i
]
->
log
=
i
?
0
:
log
;
l
->
fg_color
=
fg_color
;
l
->
outline_color
=
outline_color
;
l
->
outline_width
=
outline_width
;
l
->
log
=
log
;
}
line
=
nl
;
}
if
(
!
num_l
)
FOREACHOSD
if
(
!
num_l
)
{
struct
osd_line
*
l
=
osd_add_line
(
osd
.
state
[
i
]
,
OSD_TYPE_TEXT
);
struct
osd_line
*
l
=
osd_
set_
add_line
(
&
osd
,
OSD_TYPE_TEXT
);
l
->
u
.
text
[
0
]
=
0
;
l
->
fg_color
=
fg_color
;
l
->
outline_color
=
outline_color
;
...
...
@@ -216,7 +215,7 @@ display_msg(struct msg *msg)
if
(
msg
->
min_light
>
msg
->
max_light
)
msg
->
min_light
=
msg
->
max_light
;
FOREACHOSD
osd_show
(
osd
.
state
[
i
]
);
osd_
set_
show
(
&
osd
);
}
static
void
...
...
@@ -228,7 +227,7 @@ msg_to_stdout(struct msg *msg)
int
out_parametr_index
=
0
;
while
(
*
line
)
{
// The parser i
t
destructive, but it does not do any harm, since we display each message only once.
// The parser i
s
destructive, but it does not do any harm, since we display each message only once.
char
*
nl
=
strchr
(
line
,
'\n'
);
*
nl
++
=
0
;
...
...
@@ -261,7 +260,7 @@ static void
hide_msg
(
struct
msg
*
msg
)
{
DBG
(
"## Hiding message
\n
"
);
FOREACHOSD
osd
_clear
(
osd
.
state
[
i
]
);
osd_set
_clear
(
&
osd
);
free
(
msg
);
}
...
...
@@ -400,8 +399,24 @@ main(int argc, char **argv)
XFlush
(
dpy
);
}
osd
=
osd_set_new
(
dpy
);
FOREACHOSD
osd_set_font
(
osd
.
state
[
i
],
font_name
,
line_spacing
);
osd
=
osd_set_new
();
{
FILE
*
f
=
popen
(
"xrandr | grep
\\
connected"
,
"r"
);
char
line
[
1001
];
while
(
fscanf
(
f
,
" %1000[^
\n
]"
,
line
)
==
1
)
{
int
width
,
height
,
x
,
y
;
char
*
l
=
line
;
while
(
*
l
&&
!
(
*
l
==
' '
))
l
++
;
while
(
*
l
&&
!
(
'0'
<=*
l
&&*
l
<=
'9'
))
l
++
;
if
(
sscanf
(
l
,
"%dx%d+%d+%d"
,
&
width
,
&
height
,
&
x
,
&
y
)
==
4
)
if
(
osd
.
len
<
OSD_MAX_SET_LEN
)
{
DBG
(
"ADD screen %dx%d on %d,%d
\n
"
,
width
,
height
,
x
,
y
);
osd
.
elements
[
osd
.
len
++
]
=
display_state_new
(
dpy
,
width
,
height
,
x
,
y
);
}
}
}
struct
pollfd
pfd
=
{
.
fd
=
ConnectionNumber
(
dpy
),
...
...
@@ -443,7 +458,7 @@ main(int argc, char **argv)
{
XEvent
ev
;
XNextEvent
(
dpy
,
&
ev
);
FOREACHOSD
if
(
osd_handle_event
(
osd
.
state
[
i
]
,
&
ev
))
if
(
osd_
set_
handle_event
(
&
osd
,
&
ev
))
continue
;
if
(
ev
.
type
!=
PropertyNotify
)
continue
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment