Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This software was written by:
Hoàng Đức Hiếu <github@zahe.me>
Swift Geek <swiftgeek@gmail.com>
Aetf <aetf@unlimited-code.works>
Mirco Müller <macslow@gmail.com>
Jocelyn Falempe <jfalempe@redhat.com>

= Copyright Notice =

Expand Down
28 changes: 28 additions & 0 deletions docs/man/kmscon.1.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@
(default: &lt;Ctrl&gt;&lt;Logo&gt;Return)</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--grab-rotate-cw {grab}</option></term>
<listitem>
<para>Rotate output clock-wise: Normal -> Right -> Inverted -> Left and so on.
(default: &lt;Logo&gt;Plus)</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--grab-rotate-ccw {grab}</option></term>
<listitem>
<para>Rotate output counter-clock-wise: Normal -> Left -> Inverted -> Right and so on.
(default: &lt;Logo&gt;Minus)</para>
</listitem>
</varlistentry>
</variablelist>

<para>Video Options:</para>
Expand Down Expand Up @@ -526,6 +542,18 @@
framebuffers for a large resolution.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--rotate {orientation}</option></term>
<listitem>
<para>Select the desired orientation of the output. Available orientations
are 'normal' meaning output is not rotated, 'right' meaning output is
rotated 90° clock-wise, 'upside-down' meaning output is rotated 180°
clock-wise and 'left' meaning output is rotated 90° counter clock-wise.
This has only effect for the 'gltex' render-engine. (default: 'normal')
</para>
</listitem>
</varlistentry>
</variablelist>

<para>Font Options:</para>
Expand Down
21 changes: 21 additions & 0 deletions docs/man/kmscon.conf.1.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ font-name=Ubuntu Mono
</listitem>
</varlistentry>

<varlistentry>
<term><option>grab-rotate-cw</option></term>
<listitem>
<para>Rotate output clock-wise. (default: &lt;Logo&gt;Plus)</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>grab-rotate-ccw</option></term>
<listitem>
<para>Rotate output counter-clock-wise. (default: &lt;Logo&gt;Minus)</para>
</listitem>
</varlistentry>

<para><emphasis>### Video Options ###</emphasis></para>
<varlistentry>
<term><option>drm</option></term>
Expand Down Expand Up @@ -390,6 +404,13 @@ font-name=Ubuntu Mono
</listitem>
</varlistentry>

<varlistentry>
<term><option>rotate</option></term>
<listitem>
<para>Orientation of output to use. (default: normal)</para>
</listitem>
</varlistentry>

<para><emphasis>### Font Options ###</emphasis></para>
<varlistentry>
<term><option>font-engine</option></term>
Expand Down
1 change: 0 additions & 1 deletion src/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
struct kmscon_glyph {
struct uterm_video_buffer buf;
unsigned int width;
void *data;
};

struct kmscon_font {
Expand Down
4 changes: 1 addition & 3 deletions src/font_pango.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@

#define LOG_SUBSYSTEM "font_pango"

#define align_up4(x) (((x) + 3) & ~0x3)

struct face {
unsigned long ref;
struct shl_dlist list;
Expand Down Expand Up @@ -204,7 +202,7 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out,
glyph->width = (logical_rec.x + logical_rec.width > rec.x + face->real_attr.width) ? 2 : cwidth;
glyph->buf.width = face->real_attr.width * glyph->width;
glyph->buf.height = face->real_attr.height;
glyph->buf.stride = align_up4(glyph->buf.width);
glyph->buf.stride = glyph->buf.width;
glyph->buf.format = UTERM_FORMAT_GREY;

if (!glyph->buf.width || !glyph->buf.height) {
Expand Down
120 changes: 120 additions & 0 deletions src/font_rotate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* kmscon - rotate font
*
* Copyright (c) 2025 Jocelyn Falempe <jfalempe@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "font_rotate.h"
#include "shl_misc.h"

SHL_EXPORT
int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, shl_free_cb free_glyph)
{
int ret;

ret = shl_hashtable_new(normal, shl_direct_hash,
shl_direct_equal, free_glyph);
if (ret)
return ret;

ret = shl_hashtable_new(bold, shl_direct_hash,
shl_direct_equal, free_glyph);
if (ret)
shl_hashtable_free(*normal);
return ret;
}

SHL_EXPORT
void kmscon_rotate_free_tables(struct shl_hashtable *normal, struct shl_hashtable *bold)
{
shl_hashtable_free(normal);
shl_hashtable_free(bold);
}

SHL_EXPORT
int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, enum Orientation orientation, uint8_t align)
{
int width;
int height;
int stride;
int i, j;
uint8_t *dst, *src;
const struct uterm_video_buffer *buf = &glyph->buf;

if (orientation == OR_NORMAL || orientation == OR_UPSIDE_DOWN) {
width = buf->width;
height = buf->height;
} else {
width = buf->height;
height = buf->width;
}

stride = align * ((width + (align - 1)) / align);
vb->data = malloc(stride * height);

if (!vb->data)
return -ENOMEM;

src = buf->data;
dst = vb->data;

switch (orientation) {
default:
case OR_NORMAL:
for (i = 0; i < buf->height; i++) {
memcpy(dst, src, buf->width);
dst += stride;
src += buf->stride;
}
break;
case OR_RIGHT:
for (i = 0; i < buf->height; i++) {
for (j = 0; j < buf->width; j++) {
dst[j * stride + (width - i - 1)] = src[j];
}
src += buf->stride;
}
break;
case OR_UPSIDE_DOWN:
src += (buf->height - 1) * buf->stride;
for (i = 0; i < buf->height; i++) {
for (j = 0; j < buf->width; j++)
dst[j] = src[buf->width - j - 1];
dst += stride;
src -= buf->stride;
}
break;
case OR_LEFT:
for (i = 0; i < buf->height; i++) {
for (j = 0; j < buf->width; j++) {
dst[(height -j -1) * stride + i] = src[j];
}
src += buf->stride;
}
}
vb->width = width;
vb->height = height;
vb->stride = stride;
vb->format = buf->format;
return 0;
}

31 changes: 31 additions & 0 deletions src/font_rotate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* kmscon - rotate font
*
* Copyright (c) 2025 Jocelyn Falempe <jfalempe@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "shl_hashtable.h"
#include "text.h"

int kmscon_rotate_create_tables(struct shl_hashtable **normal, struct shl_hashtable **bold, shl_free_cb free_glyph);
void kmscon_rotate_free_tables(struct shl_hashtable *normal, struct shl_hashtable *bold);
int kmscon_rotate_glyph(struct uterm_video_buffer *vb, const struct kmscon_glyph *glyph, enum Orientation orientation, uint8_t align);
14 changes: 14 additions & 0 deletions src/kmscon_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ static void print_help()
"\t Close current session\n"
"\t --grab-terminal-new <grab> [<Ctrl><Logo>Return]\n"
"\t Create a new terminal session\n"
"\t --grab-rotate-cw <grab> [<Logo>Plus]\n"
"\t Rotate output clock-wise\n"
"\t --grab-rotate-ccw <grab> [<Logo>Minus]\n"
"\t Rotate output counter-clock-wise\n"
"\n"
"Video Options:\n"
"\t --drm [on] Use DRM if available\n"
Expand All @@ -149,6 +153,7 @@ static void print_help()
"\t error, a default mode will be used.\n"
"\t This option is incompatible with\n"
"\t --use-original-mode.\n"
"\t --rotate <orientation> [normal] normal, right, upside-down, left\n"
"\n"
"Font Options:\n"
"\t --font-engine <engine> [pango]\n"
Expand Down Expand Up @@ -646,6 +651,12 @@ static struct conf_grab def_grab_session_close =
static struct conf_grab def_grab_terminal_new =
CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_LOGO_MASK, XKB_KEY_Return);

static struct conf_grab def_grab_rotate_cw =
CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_plus);

static struct conf_grab def_grab_rotate_ccw =
CONF_SINGLE_GRAB(SHL_LOGO_MASK, XKB_KEY_minus);

static palette_t def_palette = {
[TSM_COLOR_BLACK] = { 0, 0, 0 }, /* black */
[TSM_COLOR_RED] = { 205, 0, 0 }, /* red */
Expand Down Expand Up @@ -729,6 +740,8 @@ int kmscon_conf_new(struct conf_ctx **out)
CONF_OPTION_GRAB(0, "grab-session-dummy", &conf->grab_session_dummy, &def_grab_session_dummy),
CONF_OPTION_GRAB(0, "grab-session-close", &conf->grab_session_close, &def_grab_session_close),
CONF_OPTION_GRAB(0, "grab-terminal-new", &conf->grab_terminal_new, &def_grab_terminal_new),
CONF_OPTION_GRAB(0, "grab-rotate-cw", &conf->grab_rotate_cw, &def_grab_rotate_cw),
CONF_OPTION_GRAB(0, "grab-rotate-ccw", &conf->grab_rotate_ccw, &def_grab_rotate_ccw),

/* Video Options */
CONF_OPTION_BOOL_FULL(0, "drm", aftercheck_drm, NULL, NULL, &conf->drm, true),
Expand All @@ -737,6 +750,7 @@ int kmscon_conf_new(struct conf_ctx **out)
CONF_OPTION_STRING(0, "render-engine", &conf->render_engine, NULL),
CONF_OPTION_BOOL(0, "use-original-mode", &conf->use_original_mode, true),
CONF_OPTION_STRING(0, "mode", &conf->mode, NULL),
CONF_OPTION_STRING(0, "rotate", &conf->rotate, "normal"),

/* Font Options */
CONF_OPTION_STRING(0, "font-engine", &conf->font_engine, "pango"),
Expand Down
6 changes: 6 additions & 0 deletions src/kmscon_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ struct kmscon_conf_t {
struct conf_grab *grab_session_close;
/* terminal-new grab */
struct conf_grab *grab_terminal_new;
/* rotate output clock-wise grab */
struct conf_grab *grab_rotate_cw;
/* rotate output counter-clock-wise grab */
struct conf_grab *grab_rotate_ccw;

/* Video Options */
/* use DRM if available */
Expand All @@ -149,6 +153,8 @@ struct kmscon_conf_t {
bool use_original_mode;
/* screen resolution */
char *mode;
/* orientation/rotation of output */
char *rotate;

/* Font Options */
/* font engine */
Expand Down
Loading