Compare commits

...

10 Commits

Author SHA1 Message Date
Juhani Krekelä 12a6a8f098 XXX 2022-03-07 14:47:28 +02:00
Juhani Krekelä 8ce1c5ddf3 Gracefully handle errors in initialization 2022-03-07 14:47:28 +02:00
Juhani Krekelä 110e032a14 Handle -mode 2022-03-07 14:47:28 +02:00
Juhani Krekelä 9275d115c9 Handle events 2022-03-07 14:47:28 +02:00
Juhani Krekelä dd69db99ca Minimize amount of data copied to display server 2022-03-07 14:47:28 +02:00
Juhani Krekelä 5f633be205 Further bringup and drawing routines 2022-03-07 14:47:28 +02:00
Juhani Krekelä 6c95233afe Basic bringup 2022-03-07 14:47:28 +02:00
Juhani Krekelä 50d4d868a8 Add driver to the manual page 2022-03-07 14:47:28 +02:00
Juhani Krekelä 2b52e8db95 Start work on Sortix graphics driver 2022-03-07 14:47:28 +02:00
Juhani Krekelä 0a11c4b5a5 Add sortix.c to the build system 2022-03-07 14:47:17 +02:00
10 changed files with 503 additions and 5 deletions

View File

@ -24,7 +24,7 @@ if JAVASCRIPT
links_LDADD=builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o links_LDADD=builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o
endif endif
links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c sortix.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc
# builtin.c context.c ipret.c javascr.c javascript.c md5.c md5hl.c ns.c pomocny.c regexp.c md5.h ns.h struct.h tree.h typy.h ipret.h javascript.h builtin.h builtin_keys.h # builtin.c context.c ipret.c javascr.c javascript.c md5.c md5hl.c ns.c pomocny.c regexp.c md5.h ns.h struct.h tree.h typy.h ipret.h javascript.h builtin.h builtin_keys.h
dist-hook: dist-hook:

View File

@ -76,7 +76,7 @@ bin_PROGRAMS = links
@HAIKU_GR_TRUE@links_LDADD = haiku.o @HAIKU_GR_TRUE@links_LDADD = haiku.o
@JAVASCRIPT_TRUE@links_LDADD = builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o @JAVASCRIPT_TRUE@links_LDADD = builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o
links_SOURCES = af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc links_SOURCES = af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c sortix.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc
CXXFLAGS = @CXXFLAGS@ CXXFLAGS = @CXXFLAGS@
@ -99,7 +99,7 @@ fn_impl.o fontconf.o font_inc.o framebuf.o freetype.o ftp.o gif.o grx.o \
hpux.o html.o html_gr.o html_r.o html_tbl.o http.o https.o img.o \ hpux.o html.o html_gr.o html_r.o html_tbl.o http.o https.o img.o \
imgcache.o jpeg.o jsint.o kbd.o language.o listedit.o lru.o mailto.o \ imgcache.o jpeg.o jsint.o kbd.o language.o listedit.o lru.o mailto.o \
main.o memory.o menu.o objreq.o os_dep.o pmshell.o png.o sched.o \ main.o memory.o menu.o objreq.o os_dep.o pmshell.o png.o sched.o \
select.o session.o smb.o string.o suffix.o svg.o svgalib.o terminal.o \ select.o session.o smb.o sortix.o string.o suffix.o svg.o svgalib.o terminal.o \
tiff.o types.o url.o view.o view_gr.o vms.o x.o xbm.o tiff.o types.o url.o view.o view_gr.o vms.o x.o xbm.o
@ATHEOS_GR_TRUE@links_DEPENDENCIES = atheos.o @ATHEOS_GR_TRUE@links_DEPENDENCIES = atheos.o
@JAVASCRIPT_TRUE@links_DEPENDENCIES = builtin.o context.o ipret.o \ @JAVASCRIPT_TRUE@links_DEPENDENCIES = builtin.o context.o ipret.o \
@ -457,6 +457,8 @@ session.o: session.c links.h cfg.h config.h com-defs.h os_dep.h \
os_depx.h setup.h language.h codepage.h os_depx.h setup.h language.h codepage.h
smb.o: smb.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ smb.o: smb.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h setup.h language.h codepage.h
sortix.o: sortix.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h
string.o: string.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ string.o: string.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h setup.h language.h codepage.h
suffix.o: suffix.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ suffix.o: suffix.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \

View File

@ -229,6 +229,9 @@
/* */ /* */
#undef GRDRV_GRX #undef GRDRV_GRX
/* */
#undef GRDRV_SORTIX
/* Have freetype */ /* Have freetype */
#undef HAVE_FREETYPE #undef HAVE_FREETYPE

View File

@ -215,6 +215,9 @@
/* Define if you have the dirfd function. */ /* Define if you have the dirfd function. */
#undef HAVE_DIRFD #undef HAVE_DIRFD
/* Define if you have the <display.h> header file. */
#undef HAVE_DISPLAY_H
/* Define if you have the event_base_free function. */ /* Define if you have the event_base_free function. */
#undef HAVE_EVENT_BASE_FREE #undef HAVE_EVENT_BASE_FREE
@ -596,6 +599,9 @@
/* Define if you have the <fontconfig/fontconfig.h> header file. */ /* Define if you have the <fontconfig/fontconfig.h> header file. */
#undef HAVE_FONTCONFIG_FONTCONFIG_H #undef HAVE_FONTCONFIG_FONTCONFIG_H
/* Define if you have the <framebuffer.h> header file. */
#undef HAVE_FRAMEBUFFER_H
/* Define if you have the <ft2build.h> header file. */ /* Define if you have the <ft2build.h> header file. */
#undef HAVE_FT2BUILD_H #undef HAVE_FT2BUILD_H
@ -764,6 +770,9 @@
/* Define if you have the <sys/ioctl.h> header file. */ /* Define if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H #undef HAVE_SYS_IOCTL_H
/* Define if you have the <sys/keycodes.h> header file. */
#undef HAVE_SYS_KEYCODES_H
/* Define if you have the <sys/mman.h> header file. */ /* Define if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H #undef HAVE_SYS_MMAN_H
@ -848,6 +857,9 @@
/* Define if you have the bz2 library (-lbz2). */ /* Define if you have the bz2 library (-lbz2). */
#undef HAVE_LIBBZ2 #undef HAVE_LIBBZ2
/* Define if you have the display library (-ldisplay). */
#undef HAVE_LIBDISPLAY
/* Define if you have the dl library (-ldl). */ /* Define if you have the dl library (-ldl). */
#undef HAVE_LIBDL #undef HAVE_LIBDL
@ -1173,6 +1185,9 @@
/* */ /* */
#undef GRDRV_GRX #undef GRDRV_GRX
/* */
#undef GRDRV_SORTIX
/* Have freetype */ /* Have freetype */
#undef HAVE_FREETYPE #undef HAVE_FREETYPE

107
configure vendored
View File

@ -69,6 +69,8 @@ ac_help="$ac_help
--without-haiku compile without Haiku graphics driver" --without-haiku compile without Haiku graphics driver"
ac_help="$ac_help ac_help="$ac_help
--without-grx compile without DOS GRX graphics driver" --without-grx compile without DOS GRX graphics driver"
ac_help="$ac_help
--without-sortix compile without Sortix display(1) graphics driver"
ac_help="$ac_help ac_help="$ac_help
--with-x use the X Window System" --with-x use the X Window System"
ac_help="$ac_help ac_help="$ac_help
@ -8392,6 +8394,12 @@ if test "${with_grx+set}" = set; then
if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi
fi fi
# Check whether --with-sortix or --without-sortix was given.
if test "${with_sortix+set}" = set; then
withval="$with_sortix"
if test "$withval" = no; then disable_sortix=yes; else disable_sortix=no; fi
fi
drivers="" drivers=""
@ -10416,6 +10424,105 @@ EOF
fi fi
fi fi
if test "$disable_sortix" != yes; then
for ac_hdr in display.h framebuffer.h sys/keycodes.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
echo "configure:10432: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 10437 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:10442: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
eval "ac_cv_header_$ac_safe=yes"
else
echo "$ac_err" >&5
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_header_$ac_safe=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
cat >> confdefs.h <<EOF
#define $ac_tr_hdr 1
EOF
else
echo "$ac_t""no" 1>&6
fi
done
echo $ac_n "checking for display_connect_default in -ldisplay""... $ac_c" 1>&6
echo "configure:10469: checking for display_connect_default in -ldisplay" >&5
ac_lib_var=`echo display'_'display_connect_default | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_save_LIBS="$LIBS"
LIBS="-ldisplay $LIBS"
cat > conftest.$ac_ext <<EOF
#line 10477 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char display_connect_default();
int main() {
display_connect_default()
; return 0; }
EOF
if { (eval echo configure:10488: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_lib=HAVE_LIB`echo display | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
cat >> confdefs.h <<EOF
#define $ac_tr_lib 1
EOF
LIBS="-ldisplay $LIBS"
else
echo "$ac_t""no" 1>&6
fi
if test "$ac_cv_header_display_h" = yes &&
test "$ac_cv_header_framebuffer_h" = yes &&
test "$ac_cv_header_sys_keycodes_h" = yes &&
test "$ac_cv_lib_display_display_connect_default" = yes; then
cat >> confdefs.h <<\EOF
#define GRDRV_SORTIX 1
EOF
drivers="$drivers sortix"
fi
fi
# Check whether --with-freetype or --without-freetype was given. # Check whether --with-freetype or --without-freetype was given.
if test "${with_freetype+set}" = set; then if test "${with_freetype+set}" = set; then

View File

@ -1049,6 +1049,7 @@ AC_ARG_WITH(windows, [ --without-windows compile without Windows graphics
AC_ARG_WITH(atheos, [ --without-atheos compile without Atheos graphics driver],[if test "$withval" = no; then disable_atheos=yes; else disable_atheos=no; fi]) AC_ARG_WITH(atheos, [ --without-atheos compile without Atheos graphics driver],[if test "$withval" = no; then disable_atheos=yes; else disable_atheos=no; fi])
AC_ARG_WITH(haiku, [ --without-haiku compile without Haiku graphics driver],[if test "$withval" = no; then disable_haiku=yes; else disable_haiku=no; fi]) AC_ARG_WITH(haiku, [ --without-haiku compile without Haiku graphics driver],[if test "$withval" = no; then disable_haiku=yes; else disable_haiku=no; fi])
AC_ARG_WITH(grx, [ --without-grx compile without DOS GRX graphics driver],[if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi]) AC_ARG_WITH(grx, [ --without-grx compile without DOS GRX graphics driver],[if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi])
AC_ARG_WITH(sortix, [ --without-sortix compile without Sortix display(1) graphics driver],[if test "$withval" = no; then disable_sortix=yes; else disable_sortix=no; fi])
drivers="" drivers=""
@ -1311,6 +1312,18 @@ if test "$disable_grx" != yes -a "$ac_cv_have_djgpp" = yes; then
fi fi
fi fi
if test "$disable_sortix" != yes; then
AC_CHECK_HEADERS(display.h framebuffer.h sys/keycodes.h)
AC_CHECK_LIB(display, display_connect_default)
if test "$ac_cv_header_display_h" = yes &&
test "$ac_cv_header_framebuffer_h" = yes &&
test "$ac_cv_header_sys_keycodes_h" = yes &&
test "$ac_cv_lib_display_display_connect_default" = yes; then
AC_DEFINE(GRDRV_SORTIX)
drivers="$drivers sortix"
fi
fi
AC_ARG_WITH(freetype, [ --without-freetype compile without freetype support],[if test "$withval" = no; then disable_freetype=yes; else disable_freetype=no; fi]) AC_ARG_WITH(freetype, [ --without-freetype compile without freetype support],[if test "$withval" = no; then disable_freetype=yes; else disable_freetype=no; fi])
font_rendering=INTERNAL font_rendering=INTERNAL

View File

@ -40,6 +40,10 @@ extern struct graphics_driver grx_driver;
#ifdef GRDRV_SDL #ifdef GRDRV_SDL
extern struct graphics_driver sdl_driver; extern struct graphics_driver sdl_driver;
#endif #endif
#ifdef GRDRV_SORTIX
extern struct graphics_driver sortix_driver;
#endif
/* /*
* On SPAD you must test first svgalib and then X (because X test is slow). * On SPAD you must test first svgalib and then X (because X test is slow).
@ -82,6 +86,9 @@ static struct graphics_driver *graphics_drivers[] = {
#endif #endif
#ifdef GRDRV_SDL #ifdef GRDRV_SDL
&sdl_driver, &sdl_driver,
#endif
#ifdef GRDRV_SORTIX
&sortix_driver,
#endif #endif
NULL NULL
}; };

View File

@ -52,7 +52,7 @@ Run in text mode (overrides previous \-g).
.TP .TP
\f3-driver \f2<driver name>\f1 \f3-driver \f2<driver name>\f1
Graphics driver to use. Drivers are: x, svgalib, fb, directfb, pmshell, Graphics driver to use. Drivers are: x, svgalib, fb, directfb, pmshell,
atheos. atheos, sortix.
List of drivers will be shown if you give it an unknown driver. List of drivers will be shown if you give it an unknown driver.
Available drivers depend on your operating system and available libraries. Available drivers depend on your operating system and available libraries.

350
sortix.c Normal file
View File

@ -0,0 +1,350 @@
/* sortix.c
* Sortix display(1) support
* (c) 2021 Juhani 'nortti' Krekelä
* This file is a part of the Links program, released under GPL.
*/
#include "cfg.h"
#ifdef GRDRV_SORTIX
#include <sys/keycodes.h>
#include <errno.h>
#include <stdint.h>
#include <display.h>
#include <framebuffer.h>
#include "links.h"
struct window_data
{
uint32_t window_id;
int modifiers;
uint32_t *buffer;
};
static int default_window_width = 600;
static int default_window_height = 500;
static struct display_connection* connection;
static struct display_event_handlers event_handlers;
struct graphics_driver sortix_driver;
static struct graphics_device *current_dev;
static void on_disconnect(void *ctx)
{
if (current_dev->keyboard_handler)
current_dev->keyboard_handler(current_dev, KBD_CTRL_C, 0);
}
static void on_quit(void *ctx, uint32_t window_id)
{
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
if (current_dev->keyboard_handler)
current_dev->keyboard_handler(current_dev, KBD_CLOSE, 0);
}
static void on_keyboard(void *ctx, uint32_t window_id, uint32_t codepoint)
{
(void) ctx;
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
int kbkey = KBKEY_DECODE(codepoint);
if (kbkey) {
switch (kbkey) {
case KBKEY_LALT: window_data->modifiers |= KBD_ALT; break;
case -KBKEY_LALT: window_data->modifiers &= ~KBD_ALT; break;
case KBKEY_LSHIFT: case KBKEY_RSHIFT: window_data->modifiers |= KBD_SHIFT; break;
case -KBKEY_LSHIFT: case -KBKEY_RSHIFT: window_data->modifiers &= ~KBD_SHIFT; break;
case KBKEY_LCTRL: case KBKEY_RCTRL: window_data->modifiers |= KBD_CTRL; break;
case -KBKEY_LCTRL: case -KBKEY_RCTRL: window_data->modifiers &= ~KBD_CTRL; break;
}
}
if (current_dev->keyboard_handler) {
if (kbkey) codepoint = 0;
switch (codepoint) {
case '\n': codepoint = KBD_ENTER; break;
case 127: codepoint = KBD_BS; break;
case '\t': codepoint = KBD_TAB; break;
}
switch (kbkey) {
case KBKEY_ESC: codepoint = KBD_ESC; break;
case KBKEY_LEFT: codepoint = KBD_LEFT; break;
case KBKEY_RIGHT: codepoint = KBD_RIGHT; break;
case KBKEY_UP: codepoint = KBD_UP; break;
case KBKEY_DOWN: codepoint = KBD_DOWN; break;
case KBKEY_INSERT: codepoint = KBD_INS; break;
case KBKEY_DELETE: codepoint = KBD_DEL; break;
case KBKEY_HOME: codepoint = KBD_HOME; break;
case KBKEY_END: codepoint = KBD_END; break;
case KBKEY_PGUP: codepoint = KBD_PAGE_UP; break;
case KBKEY_PGDOWN: codepoint = KBD_PAGE_DOWN; break;
case KBKEY_F1: codepoint = KBD_F1; break;
case KBKEY_F2: codepoint = KBD_F2; break;
case KBKEY_F3: codepoint = KBD_F3; break;
case KBKEY_F4: codepoint = KBD_F4; break;
case KBKEY_F5: codepoint = KBD_F5; break;
case KBKEY_F6: codepoint = KBD_F6; break;
case KBKEY_F7: codepoint = KBD_F7; break;
case KBKEY_F8: codepoint = KBD_F8; break;
case KBKEY_F9: codepoint = KBD_F9; break;
case KBKEY_F10: codepoint = KBD_F10; break;
case KBKEY_F11: codepoint = KBD_F11; break;
case KBKEY_F12: codepoint = KBD_F12; break;
}
if (codepoint)
current_dev->keyboard_handler(current_dev, codepoint, window_data->modifiers);
}
}
static void on_resize(void *ctx, uint32_t window_id, uint32_t width, uint32_t height)
{
(void) ctx;
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
if (!width || !height) return;
free(window_data->buffer);
// TODO: Overflow when multiplying
window_data->buffer = mem_alloc(width * height * sizeof(uint32_t));
current_dev->size.x2 = width;
current_dev->size.y2 = height;
if (current_dev->resize_handler)
current_dev->resize_handler(current_dev);
}
static void sortix_process_events(void *data)
{
(void) data;
if (!current_dev) return;
while (display_poll_event(connection, &event_handlers) == 0);
}
static unsigned char *sortix_init_driver(unsigned char *param, unsigned char *display)
{
if (param) {
if (sscanf(param, "%ix%i", &default_window_width, &default_window_height) != 2)
return stracpy("-mode syntax is WIDTHxHEIGHT\n");
}
(void) display; // Only used by the X11 driver
connection = display_connect_default();
if (!connection && errno == ECONNREFUSED)
display_spawn(g_argc, g_argv);
if (!connection) {
char err[256];
snprintf(err, sizeof(err), "Error connecting to display: %s\n", strerror(errno));
return stracpy(err);
}
sortix_driver.get_color = get_color_fn(sortix_driver.depth);
event_handlers.disconnect_handler = on_disconnect;
event_handlers.keyboard_handler = on_keyboard;
event_handlers.quit_handler = on_quit;
event_handlers.resize_handler = on_resize;
set_handlers(display_connection_fd(connection), sortix_process_events, NULL, NULL);
return NULL;
}
static struct graphics_device *sortix_init_device(void)
{
// TODO: Multi-window support
struct graphics_device *dev = mem_calloc(sizeof(struct graphics_device));
dev->size.x1 = 0;
dev->size.y1 = 0;
dev->size.x2 = default_window_width;
dev->size.y2 = default_window_height;
dev->clip = dev->size;
struct window_data *window_data = mem_calloc(sizeof(struct window_data));
dev->driver_data = window_data;
window_data->window_id = 0;
// TODO: Overflow when multiplying
window_data->buffer = mem_alloc(default_window_width * default_window_height * sizeof(uint32_t));
display_create_window(connection, window_data->window_id);
display_resize_window(connection, window_data->window_id, dev->size.x2, dev->size.y2);
display_show_window(connection, window_data->window_id);
current_dev = dev;
return dev;
}
static void sortix_shutdown_device(struct graphics_device *dev)
{
struct window_data *window_data = dev->driver_data;
display_destroy_window(connection, window_data->window_id);
free(window_data->buffer);
free(window_data);
}
static void sortix_shutdown_driver(void)
{
display_disconnect(connection);
}
static void sortix_after_fork(void)
{
if (connection)
display_disconnect(connection);
}
static unsigned char *sortix_get_driver_param(void)
{
return NULL; //TODO: driver parameters?
}
static int sortix_get_empty_bitmap(struct bitmap *dest)
{
// TODO: Overflow when multiplying
dest->data = mem_alloc_mayfail((size_t)dest->x * (size_t)dest->y * sizeof(uint32_t));
if (!dest->data)
return -1;
// TODO: Overflow when multiplying
dest->skip = (ssize_t)dest->x * sizeof(uint32_t);
dest->flags = 0;
return 0;
}
static void sortix_register_bitmap(struct bitmap *bmp)
{
}
static void *sortix_prepare_strip(struct bitmap *bmp, int top, int lines)
{
if (!bmp->data)
return NULL;
// TODO: Overflow when multiplying
return ((unsigned char *)bmp->data) + bmp->skip * top;
}
static void sortix_commit_strip(struct bitmap *bmp, int top, int lines)
{
}
static void sortix_unregister_bitmap(struct bitmap *bmp)
{
if (bmp->data)
mem_free(bmp->data);
}
static void sortix_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp, int x, int y)
{
CLIP_DRAW_BITMAP
struct window_data *window_data = dev->driver_data;
int pitch = dev->size.x2;
int width = bmp->x;
int height = bmp->y;
if (!width || !height)
return;
for (int bitmap_y = 0; bitmap_y < height; bitmap_y++) {
for (int bitmap_x = 0; bitmap_x < width; bitmap_x++) {
void *pixel_data = ((unsigned char*)bmp->data) + bitmap_y * bmp->skip + bitmap_x * sizeof(uint32_t);
uint32_t pixel;
memcpy(&pixel, pixel_data, sizeof(uint32_t));
// Set alpha (see sortix_fill_area() for more details)
pixel |= 0xff000000;
window_data->buffer[(y + bitmap_y) * pitch + x + bitmap_x] = pixel;
}
}
display_render_window(connection, window_data->window_id, 0, 0, dev->size.x2, dev->size.y2, window_data->buffer);
}
static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
{
CLIP_FILL_AREA
struct window_data *window_data = dev->driver_data;
int pitch = dev->size.x2;
// Links uses a pixel format where the top byte is clear
// Sortix stores alpha there, so set it to 255
uint32_t pixel = color | 0xff000000;
for (int y = y1; y < y2; y++) {
for (int x = x1; x < x2; x++) {
window_data->buffer[y * pitch + x] = pixel;
}
}
display_render_window(connection, window_data->window_id, 0, 0, dev->size.x2, dev->size.y2, window_data->buffer);
}
static void sortix_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
{
CLIP_DRAW_HLINE
sortix_fill_area(dev, x1, y, x2, y + 1, color);
}
static void sortix_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
{
CLIP_DRAW_VLINE
sortix_fill_area(dev, x, y1, x + 1, y2, color);
}
static void sortix_set_title(struct graphics_device *dev, unsigned char *title)
{
struct window_data *window_data = dev->driver_data;
display_title_window(connection, window_data->window_id, title);
}
struct graphics_driver sortix_driver =
{
(unsigned char *)"sortix",
sortix_init_driver,
sortix_init_device,
sortix_shutdown_device,
sortix_shutdown_driver,
NULL, // emergency_shutdown
sortix_after_fork,
sortix_get_driver_param,
NULL, // get_af_unix_name
NULL, // get_margin
NULL, // set_margin
sortix_get_empty_bitmap,
sortix_register_bitmap,
sortix_prepare_strip,
sortix_commit_strip,
sortix_unregister_bitmap,
sortix_draw_bitmap,
NULL, // get_color, set in sortix_init_driver()
sortix_fill_area,
sortix_draw_hline,
sortix_draw_vline,
NULL, // scroll
NULL, // set_clip_area
NULL, // flush
NULL, // block
NULL, // unblock
NULL, // set_palette
NULL, // get_real_colors
sortix_set_title,
NULL, // exec
NULL, // set_clipboard_text
NULL, // get_clipboard_text
(24 << 3) | 4, // depth: 24bpp, 4 bytes per pixel
0, 0, // size (x, y), unused
GD_DONT_USE_SCROLL | GD_UNICODE_KEYS, //flags
NULL, // param
};
#endif /* GRDRV_SORTIX */

View File

@ -1,4 +1,5 @@
NAME=links NAME=links
BUILD_LIBRARIES='libbrotli? libevent? libssl libz? libzstd? lzip? openmp? xz?' BUILD_LIBRARIES='libbrotli? libevent? libjpeg libpng librsvg? libssl libtiff? libz? libzstd? lzip? openmp? xz?'
BUILD_SYSTEM=configure BUILD_SYSTEM=configure
CONFIGURE_ARGS='--enable-graphics'
LOCATION_INDEPENDENT=true LOCATION_INDEPENDENT=true