## run-guiplan-on-x.pkg
#
# Canned logic for starting up a Mythryl process running a given GUI.
# Compiled by:
#
src/lib/x-kit/widget/xkit-widget.sublibstipulate
include package makelib::scripting_globals;
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg #
package awx = guishim_imp_for_x; # guishim_imp_for_x is from
src/lib/x-kit/widget/xkit/app/guishim-imp-for-x.pkg package dbx = sprite_theme_imp; # sprite_theme_imp is from
src/lib/x-kit/widget/xkit/theme/sprite/default/sprite-theme-imp.pkg package dcx = object_theme_imp; # object_theme_imp is from
src/lib/x-kit/widget/xkit/theme/object/default/object-theme-imp.pkg package dtx = widget_theme_imp; # widget_theme_imp is from
src/lib/x-kit/widget/xkit/theme/widget/default/widget-theme-imp.pkg package g2d = geometry2d; # geometry2d is from
src/lib/std/2d/geometry2d.pkg package gq = guiboss_imp; # guiboss_imp is from
src/lib/x-kit/widget/gui/guiboss-imp.pkg package gt = guiboss_types; # guiboss_types is from
src/lib/x-kit/widget/gui/guiboss-types.pkg package gtg = guiboss_to_guishim; # guiboss_to_guishim is from
src/lib/x-kit/widget/theme/guiboss-to-guishim.pkg package r8 = rgb8; # rgb8 is from
src/lib/x-kit/xclient/src/color/rgb8.pkg package rgb = rgb; # rgb is from
src/lib/x-kit/xclient/src/color/rgb.pkg package ted = texteditor; # texteditor is from
src/lib/x-kit/widget/edit/texteditor.pkg package oim = object_imp; # object_imp is from
src/lib/x-kit/widget/xkit/theme/widget/default/look/object-imp.pkg package sim = sprite_imp; # sprite_imp is from
src/lib/x-kit/widget/xkit/theme/widget/default/look/sprite-imp.pkg package wim = widget_imp; # widget_imp is from
src/lib/x-kit/widget/xkit/theme/widget/default/look/widget-imp.pkg nb = log::note_on_stderr; # log is from
src/lib/std/src/log.pkgherein
package run_guiplan_on_x
{
Option
#
= WINDOW_SIZE_FN g2d::Size -> g2d::Size
| WINDOW_SIZE g2d::Size
;
stipulate
Options
=
{ window_size_fn: g2d::Size -> g2d::Size,
window_size: Null_Or( g2d::Size )
};
fun process_options
(
options: List(Option),
#
{ window_size_fn,
window_size
}
)
=
{ my_window_size_fn = REF window_size_fn;
my_window_size = REF window_size;
apply do_option options
where
fun do_option (WINDOW_SIZE_FN f) => my_window_size_fn := f;
do_option (WINDOW_SIZE s) => my_window_size := THE s;
end;
end;
{ window_size_fn => *my_window_size_fn,
window_size => *my_window_size
};
};
fun default_window_size_fn (root_window_size_in_pixels: g2d::Size): g2d::Size
=
if (root_window_size_in_pixels.wide * 3
< root_window_size_in_pixels.high * 4)
#
# Tall rootwindow case:
#
wide = (root_window_size_in_pixels.wide * 9) / 10;
high = (wide * 3) / 4;
{ wide, high };
else
# Wide rootwindow case:
#
high = (root_window_size_in_pixels.high * 9) / 10;
wide = (high * 4) / 3;
{ wide, high };
fi;
herein
fun run_guiplan_on_x # PUBLIC. Open a hostwindow and run given guiplan in it.
#
(guiplan: Void -> gt::Guiplan) # This needs to be a thunk (Void -> gt::Guiplan instead of just gt::Guiplan)
# in order to allow us time to set up the required infrastructure
# (in particular, starting up guiboss-imp.pkg and millboss-imp.pkg) before we
# execute guiplan code like texteditor::with().
(options: List(Option))
=
{
(process_options
( options,
{ window_size_fn => default_window_size_fn,
window_size => NULL
}
) )
->
{ window_size_fn,
window_size
};
fun int_sink i = ();
(make_run_gun ()) -> { run_gun', fire_run_gun };
(make_end_gun ()) -> { end_gun', fire_end_gun };
windowsystem_needs = { };
windowsystem_options = [ ];
windowsystem_arg = (windowsystem_needs, windowsystem_options);
#
(awx::make_windowsystem_egg windowsystem_arg NULL) -> windowsystem_egg;
#
(windowsystem_egg ()) -> (windowsystem_exports, windowsystem_egg');
(dbx::make_sprite_theme_egg []) -> sprite_theme_egg;
(sprite_theme_egg ()) -> (sprite_theme_exports, sprite_theme_egg');
#
(dcx::make_object_theme_egg []) -> object_theme_egg;
(object_theme_egg ()) -> (object_theme_exports, object_theme_egg');
#
(dtx::make_widget_theme_egg []) -> widget_theme_egg;
(widget_theme_egg ()) -> (widget_theme_exports, widget_theme_egg');
(gq::make_guiboss_egg []) -> guiboss_egg;
(guiboss_egg ()) -> (guiboss_exports, guiboss_egg');
#
windowsystem_exports -> { guiboss_to_guishim, app_to_guishim_xspecific };
#
sprite_theme_exports -> { gui_to_sprite_theme };
object_theme_exports -> { gui_to_object_theme };
widget_theme_exports -> { theme };
#
guiboss_exports -> { client_to_guiboss };
guiboss_egg' ( { int_sink,
guiboss_to_guishim,
gui_to_sprite_theme,
gui_to_object_theme,
theme
},
run_gun', end_gun'
);
#
sprite_theme_egg' ({ int_sink, guiboss_to_guishim }, run_gun', end_gun');
object_theme_egg' ({ int_sink, guiboss_to_guishim }, run_gun', end_gun');
widget_theme_egg' ({ int_sink, guiboss_to_guishim }, run_gun', end_gun');
#
windowsystem_egg' ({ int_sink }, run_gun', end_gun');
fire_run_gun ();
(guiboss_to_guishim.root_window_size ())
->
{ root_window_size_in_pixels: g2d::Size,
root_window_size_in_mm: g2d::Size
};
# Our toplevel layout is designed to
# look best at a 4:3 aspect ration, so:
#
hostwindow_size
=
case window_size
#
THE window_size => window_size;
NULL => window_size_fn root_window_size_in_pixels;
esac;
hostwindow_hints #
= #
[
gtg::BACKGROUND_PIXEL (r8::rgb8_from_ints (128+32, 16, 32)), # Slightly desaturated green. (NOW RED.)
gtg::BORDER_PIXEL (r8::rgb8_from_ints (0, 0, 0)), # Black.
#
gtg::SITE ( { upperleft => { col => 0, row => 0 },
size => hostwindow_size,
border_thickness => 1
}
: g2d::Window_Site
)
];
(client_to_guiboss.make_hostwindow hostwindow_hints)
->
guiboss_to_hostwindow;
hostwindow_site
=
guiboss_to_hostwindow.get_window_site ();
hostwindow_site
->
{ upperleft => hostwindow_upperleft: g2d::Point,
size => hostwindow_size: g2d::Size,
border_thickness => hostwindow: Int
};
(client_to_guiboss.start_gui (guiboss_to_hostwindow, guiplan()))
->
block_until_gui_startup_is_complete;
(block_until_gui_startup_is_complete())
->
client_to_guiwindow;
block_until_mailop_fires client_to_guiboss.guiboss_done'; # Block until Gadget_To_Guiboss.shut_down_guiboss() or Millboss_To_Guiboss.shut_down_guiboss is called.
};
end; # stipulate
};
end;