#
# Transparent overlay log demo
#
# Press F1 and F2 to control the log overlay.
#

#
# Build
#
if {![have_spec linux]} {
	puts "Runs on Linux only"
	exit 0
}

set build_components {
	core init
	app/launchpad
	app/pointer
	app/rom_logger
	app/global_keys_handler
	drivers/framebuffer
	timer
	server/log_tee
	server/gui_fader
	server/gui_fb
	server/nitpicker
	server/rom_filter
	server/terminal_log
	test/nitpicker
}

build $build_components

create_boot_directory

import_from_depot [depot_user]/raw/ttf-bitstream-vera-minimal \
                  [depot_user]/pkg/terminal

#
# Generate config
#

append config {
<config>
	<parent-provides>
		<service name="CPU"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="IRQ"/>
		<service name="LOG"/>
		<service name="PD"/>
		<service name="ROM"/>
	</parent-provides>
	<default-route>
		<service name="LOG"> <child name="log_tee" /> </service>
		<service name="ROM" label_suffix="log_fader.config">
			<child name="log_fader_config"/> </service>
		<service name="ROM" label_suffix="nitpicker.config">
			<child name="nitpicker_config"/> </service>
		<service name="Gui"> <child name="nitpicker" /> </service>
		<any-service> <parent/> <any-child/> </any-service>
	</default-route>
	<default caps="128"/>
	<start name="fb_sdl" ld="no">
		<resource name="RAM" quantum="4M"/>
		<provides>
			<service name="Input"/>
			<service name="Framebuffer"/>
		</provides>
		<config width="800" height="600"/>
		<route> <any-service> <parent/> <any-child/> </any-service> </route>
	</start>
	<alias name="fb_drv" child="fb_sdl"/>
	<alias name="input_drv" child="fb_sdl"/>
	<start name="timer">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Timer"/></provides>
		<route> <any-service> <parent/> <any-child/> </any-service> </route>
	</start>

	<start name="report_rom">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Report"/> <service name="ROM"/> </provides>
		<config>
			<policy label="global_keys_handler -> hover"  report="nitpicker -> hover"/>
			<policy label="decorator_config -> xray"      report="global_keys_handler -> xray"/>
			<policy label="nitpicker_config -> xray" report="global_keys_handler -> xray"/>
			<policy label="log_fader_config -> xray" report="global_keys_handler -> xray"/>
		</config>
		<route> <any-service> <parent/> <any-child/> </any-service> </route>
	</start>

	<start name="nitpicker_config">
		<binary name="rom_filter"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="ROM"/></provides>
		<config>
			<input name="xray_enabled" rom="xray" node="xray">
				<attribute name="enabled" /> </input>

			<output node="config">
				<inline>
					<report focus="yes" xray="yes" hover="yes" />
					<domain name="pointer" layer="2" content="client" label="no" origin="pointer" />
				</inline>
				<if>
					<has_value input="xray_enabled" value="no" />
					<then>
						<inline>
							<domain name="default" layer="3" content="client" label="no" focus="click" hover="always" />
							<domain name="log"     layer="4" content="client" label="no"  focus="none"/>
						</inline>
					</then>
					<else>
						<inline>
							<domain name="log"     layer="1" content="client" label="no"/>
							<domain name="default" layer="3" content="tinted" label="yes"/>
						</inline>
					</else>
				</if>
				<inline>
					<policy label_prefix="log_" domain="log"/>
					<policy label_prefix="pointer" domain="pointer"/>
					<default-policy domain="default"/>
					<global-key name="KEY_SCROLLLOCK" label="global_keys_handler -> input"/>
					<global-key name="KEY_F1"         label="global_keys_handler -> input" />
					<global-key name="KEY_F2"         label="global_keys_handler -> input" />
				</inline>
			</output>
		</config>
		<route>
			<service name="ROM" label="xray">
				<child name="report_rom"/> </service>
			<service name="Report"> <child name="report_rom"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="nitpicker">
		<resource name="RAM" quantum="4M"/>
		<provides><service name="Gui"/></provides>
		<route>
			<service name="ROM" label="config"> <child name="nitpicker_config"/> </service>
			<service name="Framebuffer"> <child name="fb_drv" /> </service>
			<service name="Input"> <child name="input_drv" /> </service>
			<service name="Report"> <child name="report_rom" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="global_keys_handler">
		<resource name="RAM" quantum="1M"/>
		<config>
			<bool name="xray" initial="no"/>

			<press   name="KEY_SCROLLLOCK" bool="xray" change="toggle"/>
			<press   name="KEY_F1"         bool="xray" change="on"/>
			<release name="KEY_F1"         bool="xray" change="off"/>
			<press   name="KEY_F2"         bool="xray" change="toggle"/>

			<report name="xray" delay_ms="125">
				<hovered domain="panel"/>
				<hovered domain="decorator"/>
				<bool name="xray"/>
			</report>
		</config>
		<route>
			<service name="ROM" label="hover"> <child name="report_rom"/> </service>
			<service name="Gui"> <child name="nitpicker"/>  </service>
			<service name="Report"> <child name="report_rom"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>

	<start name="pointer">
		<resource name="RAM" quantum="1M"/>
	</start>

	<start name="log_fader_config">
		<binary name="rom_filter"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="ROM"/></provides>
		<config>
			<input name="xray_enabled" rom="xray" node="xray">
				<attribute name="enabled" /> </input>

			<output node="config">
				<if>
					<has_value input="xray_enabled" value="no" />
					<then>
						<attribute name="alpha" value="0" />
					</then>
					<else>
						<attribute name="alpha" value="192" />
					</else>
				</if>
			</output>
		</config>
		<route>
			<service name="ROM" label="xray"> <child name="report_rom"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="log_fader">
		<binary name="gui_fader"/>
		<resource name="RAM" quantum="5M"/>
		<provides> <service name="Gui"/> </provides>
		<route>
			<service name="ROM" label="config">
				<child name="log_fader_config" /> </service>
			<service name="Gui"> <child name="nitpicker" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="log_fb">
		<binary name="gui_fb"/>
		<resource name="RAM" quantum="4M"/>
		<provides>
			<service name="Framebuffer"/>
			<service name="Input"/>
		</provides>
		<config/>
		<route>
			<service name="Gui"> <child name="log_fader" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="terminal">
		<resource name="RAM" quantum="3M"/>
		<provides><service name="Terminal"/></provides>
		<config>
			<vfs>
				<rom name="VeraMono.ttf"/>
				<dir name="fonts">
					<dir name="monospace">
						<ttf name="regular" path="/VeraMono.ttf" size_px="16"/>
					</dir>
				</dir>
			</vfs>
		</config>
		<route>
			<service name="Input">       <child name="log_fb"/> </service>
			<service name="Framebuffer"> <child name="log_fb"/> </service>
			<any-service> <parent/> <any-child/></any-service>
		</route>
	</start>
	<start name="terminal_log">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="LOG"/></provides>
		<route>
			<service name="Terminal"> <child name="terminal" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="log_tee">
		<resource name="RAM" quantum="4M"/>
		<provides><service name="LOG"/></provides>
		<route>
			<service name="LOG" unscoped_label="log_tee">
				<child name="terminal_log"/> </service>
			<service name="LOG"> <parent/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>

	<start name="launchpad" caps="512">
		<resource name="RAM" quantum="32M"/>
		<config>
			<launcher name="testnit" ram_quota="768K" caps="128"/>
			<launcher name="rom_logger" ram_quota="768K" caps="128">
				<config rom="nitpicker.config"/>
			</launcher>
			<launcher name="rom_logger" ram_quota="768K" caps="128">
				<config rom="log_fader.config"/>
			</launcher>
		</config>
	</start>

</config>}

install_config $config

#
# Boot modules
#

# generic modules
set boot_modules {
	core ld.lib.so init
	fb_sdl
	launchpad
	log_tee
	gui_fader
	gui_fb
	nitpicker
	pointer
	report_rom
	rom_filter
	rom_logger
	terminal_log
	testnit
	timer
	global_keys_handler
}

build_boot_image $boot_modules

run_genode_until forever
