<commit_before>using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace BlackBerry.Screen
{

	public class Context : IDisposable
	{

		[DllImport ("screen")]
		static extern int screen_create_context (out IntPtr pctx, ContextType flags);

		[DllImport ("screen")]
		static extern int screen_destroy_context (IntPtr ctx);

		[DllImport ("bps")]
		static extern int screen_request_events (IntPtr ctx);

		[DllImport ("bps")]
		static extern int screen_stop_events (IntPtr ctx);

		[DllImport ("screen")]
		static extern int screen_get_domain ();

		IntPtr handle;
		public IntPtr Handle { get { return handle; } }
		private int eventDomain;

		public Action<Window> OnCloseWindow { get; set; }
		public Action<Window> OnCreateWindow { get; set; }

		public Context()
		{
			PlatformServices.Initialize ();
			if (screen_create_context (out handle, ContextType.SCREEN_APPLICATION_CONTEXT) != 0) {
				// TODO: read errno to describe problem
				throw new Exception ("Unable to create screen context");
			}
			screen_request_events (handle);
			eventDomain = screen_get_domain ();
			PlatformServices.AddEventHandler (eventDomain, HandleEvent);
		}

		void HandleEvent (IntPtr eventHandle)
		{
			var e = ScreenEvent.FromEventHandle (eventHandle);

			switch (e.Type) {
			case EventType.SCREEN_EVENT_CLOSE:
				if (OnCloseWindow != null) {
					OnCloseWindow (new Window (this, e.GetIntPtrProperty (Property.SCREEN_PROPERTY_WINDOW)));
				}
				break;
			case EventType.SCREEN_EVENT_CREATE:
				if (OnCreateWindow != null) {
					OnCreateWindow (new Window (this, e.GetIntPtrProperty (Property.SCREEN_PROPERTY_WINDOW)));
				}
				break;
			//case EventType.SCREEN_EVENT_MTOUCH_TOUCH:
			//case EventType.SCREEN_EVENT_MTOUCH_MOVE:
			//case EventType.SCREEN_EVENT_MTOUCH_RELEASE:
			default:
				Console.WriteLine ("UNHANDLED SCREEN EVENT, TYPE: {0}", e.Type);
				break;
			}

		}

		public void Dispose ()
		{
			PlatformServices.RemoveEventHandler (eventDomain);
			screen_stop_events (handle);
			screen_destroy_context (handle);
		}
	}
	
}<commit_msg>Context: Add multi-touch events.<commit_after>using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace BlackBerry.Screen
{

	public class Context : IDisposable
	{

		[DllImport ("screen")]
		static extern int screen_create_context (out IntPtr pctx, ContextType flags);

		[DllImport ("screen")]
		static extern int screen_destroy_context (IntPtr ctx);

		[DllImport ("bps")]
		static extern int screen_request_events (IntPtr ctx);

		[DllImport ("bps")]
		static extern int screen_stop_events (IntPtr ctx);

		[DllImport ("screen")]
		static extern int screen_get_domain ();

		IntPtr handle;
		public IntPtr Handle { get { return handle; } }
		private int eventDomain;

		public Action<Window> OnCloseWindow { get; set; }
		public Action<Window> OnCreateWindow { get; set; }
		public Action<int,int> OnFingerTouch { get; set; }
		public Action<int,int> OnFingerMove { get; set; }
		public Action<int,int> OnFingerRelease { get; set; }

		public Context()
		{
			PlatformServices.Initialize ();
			if (screen_create_context (out handle, ContextType.SCREEN_APPLICATION_CONTEXT) != 0) {
				// TODO: read errno to describe problem
				throw new Exception ("Unable to create screen context");
			}
			screen_request_events (handle);
			eventDomain = screen_get_domain ();
			PlatformServices.AddEventHandler (eventDomain, HandleEvent);
		}

		void HandleEvent (IntPtr eventHandle)
		{
			var e = ScreenEvent.FromEventHandle (eventHandle);

			switch (e.Type) {
			case EventType.SCREEN_EVENT_CLOSE:
				if (OnCloseWindow != null) {
					OnCloseWindow (new Window (this, e.GetIntPtrProperty (Property.SCREEN_PROPERTY_WINDOW)));
				}
				break;
			case EventType.SCREEN_EVENT_CREATE:
				if (OnCreateWindow != null) {
					OnCreateWindow (new Window (this, e.GetIntPtrProperty (Property.SCREEN_PROPERTY_WINDOW)));
				}
				break;
			case EventType.SCREEN_EVENT_MTOUCH_TOUCH:
				if (OnFingerTouch != null) {
					OnFingerTouch (e.X, e.Y);
				}
				break;
			case EventType.SCREEN_EVENT_MTOUCH_MOVE:
				if (OnFingerMove != null) {
					OnFingerMove (e.X, e.Y);
				}
				break;
			case EventType.SCREEN_EVENT_MTOUCH_RELEASE:
				if (OnFingerRelease != null) {
					OnFingerRelease (e.X, e.Y);
				}
				break;
			default:
				Console.WriteLine ("UNHANDLED SCREEN EVENT, TYPE: {0}", e.Type);
				break;
			}

		}

		public void Dispose ()
		{
			PlatformServices.RemoveEventHandler (eventDomain);
			screen_stop_events (handle);
			screen_destroy_context (handle);
		}
	}
	
}
{'fraction_non_alphanumeric': 0.10400516795865633, 'fraction_numerical': 0.0008613264427217916, 'mean_word_length': 4.059912854030501, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5606000', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1477, 'n_words': 367}