<commit_before>{-# LANGUAGE CPP, FlexibleContexts #-}

module Graphics.UI.FLTK.LowLevel.X (flcOpenDisplay, flcXid, openCallback) where
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
import Graphics.UI.FLTK.LowLevel.Utils
import Foreign.Ptr
import qualified Data.Text as T
#include "Fl_C.h"
#include "xC.h"

{# fun flc_open_display as flcOpenDisplay {} -> `()' #}

{# fun flc_xid as flcXid' {`Ptr ()'} -> `Ptr ()' #}
flcXid :: (Parent a WindowBase) => Ref a -> IO (Maybe WindowHandle)
flcXid win =
  withRef
    win
    (
      \winPtr -> do
         res <- flcXid' winPtr
         if (res == nullPtr)
         then return Nothing
         else return (Just (WindowHandle res))
    )

{# fun flc_open_callback as openCallback' { id `FunPtr OpenCallbackPrim' } -> `()' #}

openCallback :: Maybe OpenCallback -> IO ()
openCallback Nothing   = openCallback' nullFunPtr
openCallback (Just cb) = do
  ptr <- mkOpenCallbackPtr $ \cstr -> do
    txt <- cStringToText cstr
    cb txt
  openCallback' ptr<commit_msg>Return the open callback function pointer so it can be freed on the Haskell side.<commit_after>{-# LANGUAGE CPP, FlexibleContexts #-}

module Graphics.UI.FLTK.LowLevel.X (flcOpenDisplay, flcXid, openCallback) where
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
import Graphics.UI.FLTK.LowLevel.Utils
import Foreign.Ptr
#include "Fl_C.h"
#include "xC.h"

{# fun flc_open_display as flcOpenDisplay {} -> `()' #}

{# fun flc_xid as flcXid' {`Ptr ()'} -> `Ptr ()' #}
flcXid :: (Parent a WindowBase) => Ref a -> IO (Maybe WindowHandle)
flcXid win =
  withRef
    win
    (
      \winPtr -> do
         res <- flcXid' winPtr
         if (res == nullPtr)
         then return Nothing
         else return (Just (WindowHandle res))
    )

{# fun flc_open_callback as openCallback' { id `FunPtr OpenCallbackPrim' } -> `()' #}

openCallback :: Maybe OpenCallback -> IO (Maybe (FunPtr OpenCallbackPrim))
openCallback Nothing   = openCallback' nullFunPtr >> return Nothing
openCallback (Just cb) = do
  ptr <- mkOpenCallbackPtr $ \cstr -> do
    txt <- cStringToText cstr
    cb txt
  openCallback' ptr
  return (Just ptr)
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.0, 'mean_word_length': 3.466666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '7468855', 'n_tokens_mistral': 801, 'n_tokens_neox': 770, 'n_words': 212}